in reply to Regex help \b & \Q

Another way:

c:\@Work\Perl\monks>perl -wMstrict -le "use Data::Dump qw(dd); ;; my ($kw) = map qr{ (?i) (?: $_) }xms, join q{|}, map quotemeta, reverse sort qw(.NET C C++) ; ;; my $title = 'C xC Cx C C C C++ xC++ C++x C++ C++ C++ .NET x.NET .NETx + .NET .NET .NET c c++ .net' ;; my %count; $count{ uc $1 }++ while $title =~ m{ (?<! \S) ($kw) (?! \S) }xmsg; dd \%count; " { ".NET" => 5, "C" => 5, "C++" => 5 }


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: Regex help \b & \Q
by Anonymous Monk on Apr 14, 2016 at 12:38 UTC

    Hi AnomalousMonk,

    Thank you very much for all the efforts.</>

    Your code my $count = () = $title =~ m{ (?<! \S) \Q$kw\E (?! \S) }xmsig; works perfectly for me except in a couple of cases(for me).
    I have to neglect if the $kw is followed by a coma or a semicolon. Can you pls show me how to add the same to the code?

        That worked for me.
        Thank You very much for all your efforts, AnomalousMonk.