in reply to Regex help \b & \Q
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: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex help \b & \Q
by Anonymous Monk on Apr 14, 2016 at 10:47 UTC | |
|
Re^2: Regex help \b & \Q
by Anonymous Monk on Apr 14, 2016 at 10:53 UTC | |
by AnomalousMonk (Archbishop) on Apr 14, 2016 at 11:45 UTC | |
by Anonymous Monk on Apr 14, 2016 at 12:17 UTC | |
by ikegami (Patriarch) on Apr 14, 2016 at 18:29 UTC | |
by AnomalousMonk (Archbishop) on Apr 14, 2016 at 19:43 UTC | |
by rsFalse (Chaplain) on Apr 14, 2016 at 20:07 UTC | |
| |
by AnomalousMonk (Archbishop) on Apr 14, 2016 at 12:43 UTC | |
by haukex (Archbishop) on Apr 14, 2016 at 11:14 UTC | |
by AnomalousMonk (Archbishop) on Apr 14, 2016 at 11:58 UTC | |
by Anonymous Monk on Apr 14, 2016 at 12:11 UTC |