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

Re^4: regex at word boundary

by davido (Cardinal)
on Dec 08, 2005 at 05:03 UTC ( [id://515130]=note: print w/replies, xml ) Need Help??


in reply to Re^3: regex at word boundary
in thread regex at word boundary

(?!) explained:

From perlre: "A zero-width negative look-ahead assertion. For example /foo(?!bar)/ matches any occurrence of "foo" that isn't followed by "bar"." So in other words, (?!) is a negative lookahead assertion that "must not match nothing" (an impossibility).

YAPE::Regex::Explain describes it simply like this:

perl -MYAPE::Regex::Explain -e "printYAPE::Regex::Explain->new( qr/(?! +)/ )->explain();" The regular expression: (?-imsx:(?!)) 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): ---------------------------------------------------------------------- (?!) fail ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------

Dave

Replies are listed 'Best First'.
Re^5: regex at word boundary
by QM (Parson) on Dec 08, 2005 at 05:12 UTC
    "must not match nothing"
    I understand that at some level, but my brain is yelling "double negative!!". It might be better to say:
    (?!) is the negative look-ahead assertion for the null string. Since the null string matches anything and everything (including nothing), (?!) always fails.
    [I was tempted to find a symbolic representation for the null string, but I thougt that would only confuse the issue.]

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-19 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found