Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: what means this regex? $x = qr/[0-9a-f]{4|8}/

by Zaxo (Archbishop)
on Jun 09, 2006 at 14:47 UTC ( [id://554511]=note: print w/replies, xml ) Need Help??


in reply to Re^2: what means this regex? $x = qr/[0-9a-f]{4|8}/
in thread what means this regex? $x = qr/[0-9a-f]{4|8}/

If alternation worked in quantifiers, you'd want to put the eight first. The regex engine may be greedy, but it's also hasty. As soon as it matches an alternate it forgets about the remaining ones. Anything that would match the eight has already matched the four.

Translating to the intended regex,

$_ = "abc" x 4; $re_short = qr/([0-9a-f]{4}|[0-9a-f]{8})/; $re_long = qr/([0-9a-f]{8}|[0-9a-f]{4})/; print $1, $/ if /$re_short/; print $1, $/ if /$re_long/; __END__ abca abcabcab

After Compline,
Zaxo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-26 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found