Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: how to find substring using regex

by hbm (Hermit)
on Jun 22, 2011 at 17:55 UTC ( [id://910952]=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-03-28 15:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found