Per choroba's suggestion, here's this:
(but I get 4 for '.NET'; I don't see how you would get three without another look-around or assertion following the \Q...\E group).c:\@Work\Perl\monks>perl -wMstrict -le "my $title = 'C .NET Cobol .NET .NET .NETER Perl xC x.NET'; ;; for my $kw (qw(.NET C C++)) { my $count = () = $title =~ m{ (?<! \S) \Q$kw\E }xmsig; print qq{'$kw' $count}; } " '.NET' 4 'C' 2 'C++' 0
Update: Ok, you seem to have updated your OP. | Oops: Since you posted anonymously, you could not have updated the OP. Anyway... Try this for a '.NET' count of three:
c:\@Work\Perl\monks>perl -wMstrict -le "my $title = 'C .NET Cobol .NET .NET .NETER Perl xC x.NET'; ;; for my $kw (qw(.NET C C++)) { my $count = () = $title =~ m{ (?<! \S) \Q$kw\E \b }xmsig; print qq{'$kw' $count}; } " '.NET' 3 'C' 1 'C++' 0
Give a man a fish: <%-{-{-{-<
In reply to Re: Regex help \b & \Q
by AnomalousMonk
in thread Regex help \b & \Q
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |