http://www.perlmonks.org?node_id=967250

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