There's more than one way to do things | |
PerlMonks |
Re: Patternmatching IPaddressesby rjt (Curate) |
on Jun 22, 2013 at 23:42 UTC ( [id://1040303]=note: print w/replies, xml ) | Need Help?? |
You might try explicitly matching either the beginning of the string or a space with (^|\s):
Note that if your Perl is older than 5.014, and hence you can not use the /r modifier, you can replace the print() statement with this: print map { s/(^|\s)\d+\.\d+/$1X.X/g; $_ } <DATA>;If you need stricter validation of your input data, the following regexp will only match lines that have two IP addresses and nothing else: s/^\d+\.\d+\.(\d+\.\d+) \d+\.\d+\.(\d+\.\d+)$/X.X.$1 X.X.$2/;Note that the /g modifier is not necessary in this case as the regexp covers the entire string.
In Section
Seekers of Perl Wisdom
|
|