Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: "While" effect on regex?

by roboticus (Chancellor)
on Feb 17, 2013 at 00:01 UTC ( #1019085=note: print w/ replies, xml ) Need Help??


in reply to "While" effect on regex?

lightoverhead:

Without the 'g' modifier, the m/.../ operator simply reports whether the string matches or not. Unless you change the string, it will *always* match or *always* fail. If you read perlre, it'll refer you to perlretut. In there it says:

Global matching

The final two modifiers "//g" and "//c" concern multiple matches. The modifier "//g" stands for global matching and allows the matching operator to match within a string as many times as possible. In scalar context, successive invocations against a string will have `"//g" jump from match to match, keeping track of position in the string as it goes along. You can get or set the position with the "pos()" function.

The relevent bit is the italicized bit. It's telling you that with the g operator, the match remembers where it left off, and the next time you match with the g operator, it will proceed from that point.

Long story short: that's what the 'g' modifier does!

...roboticus

When your only tool is a hammer, all problems look like your thumb.


Comment on Re: "While" effect on regex?
Replies are listed 'Best First'.
Re^2: "While" effect on regex?
by lightoverhead (Monk) on Feb 17, 2013 at 00:08 UTC

    roboticus

    Your answer is very clear! Thanks a lot!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2015-08-02 14:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...













    Results (2 votes), past polls