Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2004
    Posts
    48

    Unanswered: replacing text????

    hi all..
    i want to replace some texts from a string
    4eg
    $str='this is my test document and was created in perl and it is very goodis"
    out of this string i want to replace all 'is' and 'was' with 'are' how i wil do it
    rem ny string contains substrings eg (is in 'goodis' Ii don't want to replace it
    pls help me
    thnks in advance
    jag

  2. #2
    Join Date
    Feb 2006
    Posts
    56
    use the word boundary operator \b

    Code:
    my $str = 'this is my test document and was created in perl and it is very goodis';
    $str =~ s/\bis|was\b/are/ig;
    print $str;
    or you could try and use spaces:

    Code:
    my $str = 'this is my test document and was created in perl and it is very goodis';
    $str =~ s/\sis|was\s/are/ig;
    print $str;
    but the \b operator is generally used for this type of substitution. Any regexp resource or tutorial should have it listed.

  3. #3
    Join Date
    Jan 2006
    Posts
    32
    I assume you want to make the change in perl.

    use
    Code:
    $string =~ s/\bis\b/was/g;
    \b is a zero width match that matches only on a word boundary.



    .

  4. #4
    Join Date
    Jul 2004
    Posts
    48

    thnks!!!!!

    hi all
    i'd try it and its working thnk u verymuch
    but the problem is whn i add more choices some textes(means substrings) are missing
    neway thnks 4 ur help
    bye
    jag

  5. #5
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    Can you post some more details about the problem?

    You should post some Dummy data and code...
    board.perl-community.de - The German Perl-Community

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •