Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Perl Monk, Perl Meditation
 
PerlMonks  

Re: weird regex question

by JavaFan (Canon)
on Apr 25, 2012 at 16:25 UTC ( #967111=note: print w/ replies, xml ) Need Help??


in reply to weird regex question

If you use !$!, only $! get interpolated, not the entire expression. In your case, $!, in string context, will be the empty string. So, you end up with

/^.{!}(.{5})/
which is not going to match. If you want to interpolate the expression, use:
/^.{@{[!$!]}}(.{5})/


Comment on Re: weird regex question
Select or Download Code
Re^2: weird regex question
by Anonymous Monk on Apr 25, 2012 at 17:07 UTC
    hmm kinda makes sense, so how would i do the 5?
      What do you mean, how would I do the 5?
        ohh nevermind i figured it out.. thanks :D
      1 and 5
      my $string = "hello world"; print $string =~ /^.{@{[!$[]}}(.{${\($]<<$]>>$])}})/; # 'ello '
      or print $]>>$?;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://967111]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2013-05-25 06:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (519 votes), past polls