Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: How regex works in array mode?

by JavaFan (Canon)
on Apr 26, 2012 at 08:37 UTC ( #967269=note: print w/ replies, xml ) Need Help??


in reply to Re^2: How regex works in array mode?
in thread How regex works in array mode?

How will I get rid all the capturing parens?
An easy way, one that should also speed up your pattern, make it more understandable, and saves typing, is to replace
([0-9]{3}|[0-9]{2}|[0-9]{1})
with
[0-9]{1,3}
Of course, you could also use the Regexp::Common module: but be aware, unlike your pattern, the one in Regexp::Common rejects invalid IP addresses.


Comment on Re^3: How regex works in array mode?
Select or Download Code
Re^4: How regex works in array mode?
by astronogun (Sexton) on Apr 26, 2012 at 09:12 UTC
    I already replace it and the output is:
    ip:192.168.243.1

    but it doesn't print the "ip:192.168.243.2" Is it possible to print the next value in the array? Thanks

    or is this output possible?

    ip:192.168.243.1 ip:192.168.243.2
      Perhaps you haven't replaced it correctly?
      use 5.010; my @lines = ("ip:192.168.243.1", "ip:192.168.243.2" =~ /(ip:[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/); say for @lines; __END__ ip:192.168.243.1 ip:192.168.243.2
      Do note that ip:192.168.243.2 is in @lines only because the pattern matches the entire string. And do note that "ip:192.168.243.1" is not subject to any matching. In fact, the assignment to @lines is equivalent with:
      my @lines; $lines[0] = "ip:192.168.243.1"; push @lines, $1 if "ip:192.168.243.2" =~ /(ip:[0-9]{1,3}\.[0-9]{1,3}\. +[0-9]{1,3}\.[0-9]{1,3})/;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-07-12 02:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (238 votes), past polls