in reply to Regex help \b & \Q
Ok, here's yet another fix to my regex. I noticed that '.NET;.NET;' and similar are not counted properly. That's because the (?<! \S) look-behind doesn't allow for a comma or semicolon. Easily fixed:
(So... How should C;x C++,x .NET;x etc. be handled?)c:\@Work\Perl\monks>perl -wMstrict -le "my $s = '.net,.Net; .NET;.net, .NET x.NET .NETx x.NET; x.NET,'; ;; for my $kw (qw(.NET C C++)) { my $count = () = $s =~ m{ (?: (?<! \S) | (?<= [,;])) \Q$kw\E (?: (? +! \S) | (?= [,;])) }xmsig; print qq{'$kw' $count}; } " '.NET' 5 'C' 0 '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 17:14 UTC |