Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: weird regex question

by kennethk (Monsignor)
on Apr 25, 2012 at 16:17 UTC ( #967108=note: print w/ replies, xml ) Need Help??


in reply to weird regex question

You can get an explanation of any regular expression using YAPE::Regex::Explain. In this case, it outputs:

The regular expression: (?-imsx:^.{!}(.{5})) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- . any character except \n ---------------------------------------------------------------------- {!} '{!}' ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- .{5} any character except \n (5 times) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------

The issue is that the $! variable is interpolated to an empty string but ! operator doesn't get interpolated as such in the regular expression. Essentially, your modification is actually looking for the string literal {!}.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re: weird regex question
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-12-27 09:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls