Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Regexp question,get 2nd match

by Ratazong (Monsignor)
on Jul 24, 2012 at 10:56 UTC ( #983369=note: print w/replies, xml ) Need Help??


in reply to Regexp question,get 2nd match

If (\d+\.\d+\.\d+\.\d+\:\d+) matches one ip-address, then (\d+\.\d+\.\d+\.\d+\:\d+)(\d+\.\d+\.\d+\.\d+\:\d+) will match two(*). The only thing you have to consider that there are some other characters in between. You may get them with .*?. So your final code could be:

if (m/(\d+\.\d+\.\d+\.\d+\:\d+).*?(\d+\.\d+\.\d+\.\d+\:\d+)/){ push @ipaddress,$2;
HTH, Rata

update: (*) well, not exactly, as there is a seperator missing between both (and the regex-engine cannot determine where ip1 ends and where ip2 starts) ... but that is taken care off in the next step...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://983369]
help
Chatterbox?
[stevieb]: interestingly enough, someone else got my Devel::Examine:: Subs distribution for their PRC, and I applaud the change. This dist is extremely complicated and mostly obfu, but the person doing it understood PPI enough to change...
[stevieb]: ...something I had overlooked in the extreme depths of the core functionality. After merging, then a couple of extra tweaks, I still have 100% test coverage. Yay for people who write tests!

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2017-01-24 01:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (199 votes). Check out past polls.