Greetings Monks!
I am new to perl & trying to do some regex codes. Now I need your help to proceed further. A full day now & I didn't find a solution yet for this.
Ok, here is it!
This code works,
$title =~ /\b$kw\b/g;
This code also works
$title =~ /\Q$kw/g;
How to make this both work in a single code ?
ie, something like this,
$title =~ /\Q\b$kw\b/g; (BTW, this code won't work for me!)
What I want to achieve,
1) Match words(& count them) in a string but don't check in the substings. (reason why I used \b)
2) To be able to escape certain regex characters (like +) and consider them when matching words (reason why I used \Q)
An example scenario,
When you give .NET as $kw, the count should be 3 and not 4
when you give C++, the count should be 0 instead of 2
When you give C, the count should be 1
my $kw = ".NET"; # For different scenarios pls use C (& then C++) instead of .NET for $ +kw my $title = "C .NET Cobol .NET .NET .NETER Perl"; my $count = () = $title =~ /$kw/ig; print $count; die;
Any help is greatly appreciated.
Thank you
In reply to Regex help \b & \Q by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |