Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^4: Seeker of Regex Wisdom (strings which don't form specific patterns)

by AnomalousMonk (Archbishop)
on Aug 13, 2015 at 10:04 UTC ( [id://1138404]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Seeker of Regex Wisdom (strings which don't form specific patterns)
in thread Seeker of Regex Wisdom (strings which don't form specific patterns)

perl -ne 'print if /(\d{1,3}\.){3}(\d{1,3})/ and $1 < 256 and ... and $4 < 256;'

Unfortunately, capture groups don't change their numbering under a counted quantifier (a misapprehension I've suffered more than once), so it's necessary to use four explicit captures for the above to work:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "$_ = '12.34.56.78'; ;; /(\d{1,3}\.){3}(\d{1,3})/; dd [ $1, $2, $3, $4 ]; ;; /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/; dd [ $1, $2, $3, $4 ]; " ["56.", 78, undef, undef] [12, 34, 56, 78]


Give a man a fish:  <%-(-(-(-<

Replies are listed 'Best First'.
Re^5: Seeker of Regex Wisdom (strings which don't form specific patterns)
by shmem (Chancellor) on Aug 13, 2015 at 12:29 UTC
    Unfortunately, capture groups don't change their numbering under a counted quantifier

    One way to overcome that is keeping track oneself:

    $_ = '192.168.2.111'; my @l; /^(?:([01]?\d\d?|2[0-4]\d|25[0-5])(?{push@l,$1})\.){3}([01]?\d\d?|2[0- +4]\d|25[0-5])$/; print join('-',@l,$2),"\n"; __END__ 192-168-2-111
    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re^5: Seeker of Regex Wisdom (strings which don't form specific patterns)
by Laurent_R (Canon) on Aug 13, 2015 at 10:20 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-19 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found