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:

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
(So... How should  C;x C++,x .NET;x etc. be handled?)


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

    Wow, well spotted AnomalousMonk. Actually I had forgotten to include this scenario. Thank you.

    regarding C;x C++,x .NET;x
    C should be 1
    C++ should be 1
    .NET also should be 1

    Thank You again