SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Search/Replace

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2009
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Search/Replace

    Hi. I have a piece of code to search and replace certain words.

    I want the search to be both global but also case insensitive.

    I can make it insensitive, but the global search won't work. This is the code I have:

    Code Perl:
    if($comments =~ m/bad/i) {
        $comments =~ s/bad/###/g;
    }

    Any help would be brilliant. Thanks in advance!

  2. #2
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Add the 'i' to the global search too. There is really no need for the "if" condition, just do the replacement:

    $comment =~ s/bad/###/ig;


Bookmarks

Posting Permissions

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