Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Regex redux

by petral (Curate)
on Nov 20, 2002 at 02:36 UTC ( [id://214333]=note: print w/replies, xml ) Need Help??


in reply to Matching an IP address

if ( @ips = $line =~ /[\d.]{7,15}/g ) { $client_ip{$ips[0]}{$iteration}++; . . . }
If you need to check the validity of the line, you can wrap that in something like (using the regex from Mastering Reg Exps as cited here):
$numrx = qr/[01]?\d\d?|2[0-4]\d|25[0-5]/; $iprx = qr/($numrx\.){3}$numrx/; if ( $line =~ /^(\s*($iprx):\d+\s*->){2}\s*$iprx/ ) { . . . }
Or, of course combine them: if ( $line =~ /^\s*($iprx):\d+\s*->\s*($iprx):\d+\s*->\s*($iprx)/ ) {
  p

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2024-04-18 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found