in reply to Matching problems

The regexp you're using will get a false hit on thistle.

Try

my $search = "this"; my $data = "This is the test text for THIS routine."; my $bs = "<b>"; my $be = "</b>"; my $count = $data =~ s/\b($search)\b/$bs\1$be/gi;
The backreference (\1) preserves case.


Update: Kanji is right. Use $1 instead of \1.

Replies are listed 'Best First'.
Re: Re: Matching problems
by Kanji (Parson) on Apr 20, 2002 at 00:17 UTC

    $1 also preserves case, with the added benefit of being -w / use warnings;-friendly!

    my $count = $data =~ s/\b($search)\b/$bs$1$be/gi;

        --k.


Re: Re: Matching problems
by Anonymous Monk on Apr 20, 2002 at 04:22 UTC
    This is working quite well, I appreciate the help. An to the rest of the monks that responded thanks also. Using ALL of your reply's I was able to get a little better grasp on how regexp works. I still have some reading and studying to do, but I have accelerated my learning a bit by reading all the helpful information here. Thanks!