in reply to Slurping file using regular expressions for array or variables
($IPADDR,$MACADDR,$OS,$OSDETL) = $TEXT =~ /(192\.168\.1\.[\d]+).*?([\d]2:[\d]2:[\d]2:[\d]2:[\d]2:[\d]2)/g;but it doesn't work. It will work if I only use
@matches = ( $TEXT =~ /(192\.168\.1\.[\d]+)/g); foreach my $val (@matches) { print "$val\n";But if I try to match another string in the same regular expression it fails. For example, this doesn't work:
@matches = ( $TEXT =~ /(192\.168\.1\.[\d]+).*?([\d]2:[\d]2:[\d]2:[\d]2:[\d]2:[\d]2)/g);
If that's what you tried to write, amended to close the code tags as kennethk suggested, why are you using character classes when \d would work and \d{2} might do what you want?
And not just BTW, were you specify \d+ the regex engine would any number of digits until some other character intervenes or it hits the end of the string... and .*? merely limits the number of matches to the dot (anything) to as few as possible before taking up with your [\d]2:s again.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Slurping file using regular expressions for array or variables
by firefli (Initiate) on Apr 04, 2014 at 17:48 UTC | |
by ww (Archbishop) on Apr 04, 2014 at 19:20 UTC | |
by firefli (Initiate) on Apr 04, 2014 at 20:34 UTC | |
by ww (Archbishop) on Apr 05, 2014 at 01:49 UTC |