in reply to Re^3: Regex help \b & \Q (updated)
in thread Regex help \b & \Q
The problem with using (?:^|\s) and (?:\s|$) as delimiter patterns is that \s in the middle of a string requires and consumes a whitespace character. If only a single whitespace character separates patterns that are intended to match, some matches will be missed:
c:\@Work\Perl\monks>perl -wMstrict -le "my $title = 'C C C C++ C++ C++ .NET .NET .NET'; ;; for my $kw (qw(.NET C C++)) { my $count = () = $title =~ m{ (?:^|\s) \Q$kw\E (?:\s|$) }xmsig; print qq{'$kw' $count}; } " '.NET' 2 'C' 2 'C++' 2
Give a man a fish: <%-{-{-{-<
|
|---|