Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: regex trouble

by dewey (Pilgrim)
on May 30, 2007 at 16:43 UTC ( [id://618240]=note: print w/replies, xml ) Need Help??


in reply to Re: regex trouble
in thread regex trouble

I just discovered quotemeta as a result of the recent functional functions node, so I'm pleased to see it in use here.

I have a question about your solution, though. When I print "$pattern\n", I get
\,|\||\:|\>|\]\[|_\|_
To me, it's odd that this works correctly with the comma, colon, and chevron escaped. I'll go look at perlre, but why doesn't it matter that these are escaped?

~dewey

Replies are listed 'Best First'.
Re^3: regex trouble
by graff (Chancellor) on May 31, 2007 at 03:32 UTC
    In a regex, "\," is exactly equivalent to "," -- and likewise for colon and angle brackets. Those characters do not have any "magical" force in the regex syntax when used without escapes (in contrast to period, asterisk, square brackets and so on), nor do they have any special meaning when preceded by backslash (in contrast to "n", "t", "b", "d" and so on).

    Meanwhile, quotemeta is a more-or-less general-purpose function -- according to the manual, it 'Returns the value of EXPR with all non-"word" characters backslashed. (That is, all characters not matching "/[A-Za-z_0-9]/" will be preceded by a backslash in the returned string, regardless of any locale settings.)'

    (updated to fix display of square brackets in last paragraph)

      I see. Thanks.

      ~dewey

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-20 05:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found