astronogun has asked for the wisdom of the Perl Monks concerning the following question:
Hi, Once again I would like to seek for help..
It's simple I would like to know how regex works in perl in array mode.
I have this code wherein it will display the word ip: and the url x.x.x.x I have two inputed in my @lines and both are should be matched.. but the problem is I'm getting different result. Here's a simple code that I'm currently testing right now.
use strict; use warnings; my @lines = ("ip:192.168.243.1", "ip:192.168.243.2" =~ /(ip:([0-9]{3}| +[0-9]{2}|[0-9]{1})\.([0-9]{3}|[0-9]{2}|[0-9]{1})\.([0-9]{3}|[0-9]{2}| +[0-9]{1})\.([0-9]{3}|[0-9]{2}|[0-9]{1}))/); print "@lines\n";
and the output is:
ip:192.168.243.1 ip:192.168.243.2 192 168 243 2
Suppose to be the "ip:192.168.243.1 ip:192.168.243.2" part is the one what I want it to be except for the next one "192 168 243 2"
I tried putting m and the regex code but it will just display "ip:192.168.243.1" even if the other value in the array is also matched (ip:192.168.243.2)
I tested the regex via http://regexpal.com/ and its working fine (I think hehe!) Hope you could help me learn how this regex works :) thank you so much
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How regex works in array mode?
by JavaFan (Canon) on Apr 26, 2012 at 07:06 UTC | |
by astronogun (Sexton) on Apr 26, 2012 at 08:32 UTC | |
by JavaFan (Canon) on Apr 26, 2012 at 08:37 UTC | |
by astronogun (Sexton) on Apr 26, 2012 at 09:12 UTC | |
by JavaFan (Canon) on Apr 26, 2012 at 10:02 UTC | |
|
Re: How regex works in array mode?
by jwkrahn (Abbot) on Apr 26, 2012 at 08:42 UTC | |
by astronogun (Sexton) on Apr 26, 2012 at 10:14 UTC | |
|
Re: How regex works in array mode?
by brx (Pilgrim) on Apr 26, 2012 at 09:09 UTC |