| Regular expressions and pattern matchingFind or set the offset for the last/next m//g searchDaftar Isi - pos
Returns the offset of where the last m//g search left off for thevariable in question ($_ is used when the variable is notspecified). Note that 0 is a valid match offset. undef indicatesthat the search position is reset (usually due to match failure, butcan also be because no match has yet been run on the scalar). pos directly accesses the location used by the regexp engine tostore the offset, so assigning to pos will change that offset, andso will also influence the \G zero-width assertion in regularexpressions. Both of these effects take place for the next match, soyou can't affect the position with pos during the current match,such as in (?{pos() = 5}) or s//pos() = 5/e .
Setting pos also resets the matched with zero-length flag, describedunder Repeated Patterns Matching a Zero-length Substring in perlre. Because a failed m//gc match doesn't reset the offset, the returnfrom pos won't change either in this case. See perlre andperlop. |
| |
|