Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^4: Regex help \b & \Q

by AnomalousMonk (Archbishop)
on Apr 14, 2016 at 11:58 UTC ( [id://1160390]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Regex help \b & \Q (updated)
in thread Regex help \b & \Q

The problem with using  (?:^|\s) and  (?:\s|$) as delimiter patterns is that  \s in the middle of a string requires and consumes a whitespace character. If only a single whitespace character separates patterns that are intended to match, some matches will be missed:

c:\@Work\Perl\monks>perl -wMstrict -le "my $title = 'C C C C++ C++ C++ .NET .NET .NET'; ;; for my $kw (qw(.NET C C++)) { my $count = () = $title =~ m{ (?:^|\s) \Q$kw\E (?:\s|$) }xmsig; print qq{'$kw' $count}; } " '.NET' 2 'C' 2 'C++' 2


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1160390]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found