in reply to how to find substring using regex
Your code would increment $cnt once if the expression is true (matches one or more times). You could turn it around like this:
$cnt++ while $str=~/harsh/g;
Note also that you don't need to store the matches (with parentheses) for what you are doing.
And the '+' modifier in your example would match 'harsh' and 'harshhhhhhhhhh'. Is that what you meant?
|
|---|