On 16/03/2011 15:08, Shawn H Corey wrote:
On 11-03-16 11:05 AM, John W. Krahn wrote:
Jim wrote:
$old_ip_address = "1.2.3.4";
$new_ip_address = "5.6.7.8"
$old_ip_address_regexp = $old_ip_address;
$old_ip_address_regexp =~ s/\./\\./ig;
$read_line =~ s/(\D*)$old_ip_address_regexp(\D*)/$1$new_ip_address$2/ig;

(\D*) won't work because it can match zero characters. Just use (\D)

Use /(\D|^)$old_ip_address_regexp(\D|$)/

(?<!\d) and (?!\d) also match at the ends of a string, so

  /(?<!\d)\Q$old_ip_address_regexp\E(?!\d)/

Rob

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to