in reply to Re: Global regex giving up too soon
in thread Global regex giving up too soon
In scalar context, each execution of m//g finds the next match, returning true if it matches, and false if there is no further match. The position after the last match can be read or set using the pos() function; see perlfunc/pos. A failed match normally resets the search position to the beginning of the string, but you can avoid that by adding the /c modifier (e.g. m//gc). Modifying the target string also resets the search position.Note that //c is only documented to work with m//g, and even then only in scalar context (though it actually works even in list context).
Update: perlre says it better than I did. Almost at the very top:
For reference on how regular expressions are used in matching operations, plus various examples of the same, see discussions of m//, s///, qr// and ?? in perlop/"Regexp Quote-Like Operators".Matching operations can have various modifiers. Modifiers that relate to the interpretation of the regular expression inside are listed below. Modifiers that alter the way a regular expression is used by Perl are detailed in perlop/"Regexp Quote-Like Operators" and perlop/"Gory details of parsing quoted constructs".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Global regex giving up too soon
by Wassercrats (Initiate) on Jan 21, 2004 at 20:47 UTC | |
by woolfy (Chaplain) on Jan 22, 2004 at 09:39 UTC |