Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: regex not matching special char

by Anonymous Monk
on Dec 14, 2012 at 08:50 UTC ( #1008802=note: print w/ replies, xml ) Need Help??


in reply to Re^2: regex not matching special char
in thread regex not matching special char

Am I asking too much of Perl regex?

;) No, is Perl regex asking too much by asking you to know what you're asking for ? *zing*

perlrequick

Luckily YAPE::Regex::Explain handles these

use YAPE::Regex::Explain; print YAPE::Regex::Explain->new( '\b\$AVG' )->explain; __END__ The regular expression: (?-imsx:\b\$AVG) 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): ---------------------------------------------------------------------- \b the boundary between a word char (\w) and something that is not a word char ---------------------------------------------------------------------- \$ '$' ---------------------------------------------------------------------- AVG 'AVG' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
use YAPE::Regex::Explain; print YAPE::Regex::Explain->new( '\w?\$AVG\b' )->explain; __END__The regular expression: (?-imsx:\w?\$AVG\b) 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): ---------------------------------------------------------------------- \w? word characters (a-z, A-Z, 0-9, _) (optional (matching the most amount possible)) ---------------------------------------------------------------------- \$ '$' ---------------------------------------------------------------------- AVG 'AVG' ---------------------------------------------------------------------- \b the boundary between a word char (\w) and something that is not a word char ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------


Comment on Re^3: regex not matching special char
Select or Download Code
Re^4: regex not matching special char
by mnooning (Sexton) on Dec 14, 2012 at 12:33 UTC

    Thanks for the tip on YAPE::Regex::Explain.

    As kennethk pointed out - reading between the lines - the key is to know that a back slashed special character will not be taken as a word character, and hence will be seen as a word boundary itself. That is why the simple \b does not work.

    Armed with a definitive answer as to what is happening, a simple work around can be constructed. In my case the strings I am looking for are actual directory names. I can split on the directory separator.

    Thanks again.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2014-07-23 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (140 votes), past polls