in reply to Re^2: Regex help \b & \Q
in thread Regex help \b & \Q
Hi Anonymous,
\b matches between a \w (in this case "C") and a \W (in this case "+"). If your keywords are always separated by whitespace, something like the following might work. It would be helpful if you could post several example inputs with their expected outputs.
Update: The following does not work correctly if the input string contains multiple instances of $kw separated by a single \s. Thanks to AnomalousMonk for catching that!
my $kw = 'C'; # or use C++ my $title = ".net C .NET Cobol .NET C++ .NET .NETER Perl IT x.NET .net +"; my $count = () = $title =~ m{ (?:^|\s) \Q$kw\E (?:\s|$) }xmsig; print "$count\n"; # prints "1" for both C and C++
Hope this helps,
-- Hauke D
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Regex help \b & \Q
by AnomalousMonk (Archbishop) on Apr 14, 2016 at 11:58 UTC | |
|
Re^4: Regex help \b & \Q
by Anonymous Monk on Apr 14, 2016 at 12:11 UTC |