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

I'm afraid I do not understand your problem. If I take ikegami's code and modify it slightly so as not to depend on the existence of "apache.txt":

while (<DATA>) { s/\bis\b/are/g; print; } __DATA__ Apache is a modular server. This implies that only the most basic func +tionality is included in the core server. is it so ? Extended features are available through modules which can be loaded in +to Apache. By default, a base set of modules is included in the server at compile-time. If the server is compiled to u +se dynamic ally loaded modules, then modules can be compiled separately and added at any time using the LoadModule directi +ve. Otherw ise, Apache must be recompiled to add or remove modules. Configuration directives may be included conditional o +n a presen ce of a particular module by enclosing them in an <IfModule> block.

I get the following output (where clearly "is" has been replaced by "are" throughout):

Apache are a modular server. This implies that only the most basic fun +ctionality are included in the core server. are it so ? Extended features are available through modules which can be loaded in +to Apache. By default, a base set of modules are included in the server at compile-time. If the server are compiled to +use dynami c ally loaded modules, then modules can be compiled separately and added at any time using the LoadModule directi +ve. Otherw ise, Apache must be recompiled to add or remove modules. Configuration directives may be included conditional o +n a presen ce of a particular module by enclosing them in an <IfModule> block.

How does this differ from your desired output?

HTH,

planetscape

Replies are listed 'Best First'.
Re^4: regex is not producing desired output
by manishrathi (Beadle) on Jan 26, 2010 at 00:37 UTC
    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' ?
      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