in reply to Re^3: regex is not producing desired output
in thread regex is not producing desired output

Apache is a modular server. This implies that only the most basic functionality is included in the core server. is it so ?

On this file , when I use following code
open(file, "apache.txt") ; @modify = <file> ; print @modify ; foreach(@modify){ chomp($_); $_ =~ s/\bis\b/are/g ; # $_ =~ s/^is$/are/g ; } print @modify ;

This will replace 'is" with 'are' which I tested correcty. Now when I comment out "$_ =~ s/\bis\b/are/g ;" and uncomment "$_ =~ s/^is$/are/g ;" ,'is' will not be replaced by 'are' , which was my original problem. As ^ will look at the beginning of string and $ will look at the end of string.

If I add 'is' at the beginning and end of the string, will then 'is' be replaced with 'are' in the string ?

 is Apache is a modular server. This implies that only the most basic functionality is included in the core server. is it so ? is
If I use regex "$_ =~ s/^is$/are/g ;" on this text, will it replace 'is' with 'are' as this string has 'is' at the beginning and end as well, which satisfies the regex condition.
I tried, but it did not replace is with 'are'. So why did it not replace 'is' with 'are' ?

Replies are listed 'Best First'.
Re^5: regex is not producing desired output
by ikegami (Patriarch) on Jan 26, 2010 at 06:07 UTC
    You didn't ask to match an "is" at the start of the string or an "is" at the end of the string. You asked to match one that is both.
    >perl -le"$_='is'; s/^is$/are/g; print" are >perl -le"$_='is is is'; s/^is$/are/g; print" is is is >perl -le"$_='is is is'; s/^is|is$/are/g; print" are is are