View Single Post
  #1 (permalink)  
Old March 5th, 2007, 05:17 PM
CaNNaC CaNNaC is offline
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Regular Expression in Perl

Hi everyone,
I am a new perl programmer and I have a problem with regular expressions in perl.
I wrote a regular expression in order to match a certain part of a string and then I wanted to be able get and change that part of the string (that is, matched substring), but I don't know how to get the matched substring and change it in perl. (I wrote the regular expression and it is working correctly and doing its job well)
For exampple;
Let's assume our string is, $str = "The men in the room looked at the Men in the street.", and I wrote a reg. expr. that matches /Men/, and I want to substitute -en-(in Men) to -an-. So, if I write the following code;
<code> if($str =~ m/Men/) {
          $str = s/en/an; } </code>
this code will change the -en- that is the first one (in men) in the string which is I don't want.

As a result, my problem is the same, I wrote a reg. expr., it matches a substr. but I am not able to change the content of that substr.

Please help, I know there is a way to make this in perl but I couldn't find it.

Thanks.




Reply With Quote