Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Bgeinner regex question

by choroba (Cardinal)
on Mar 27, 2016 at 19:04 UTC ( [id://1158893]=note: print w/replies, xml ) Need Help??


in reply to Bgeinner regex question

You're on the right track. The global matching starts at the position where the last match ended. You can use \G to mark the position, but you can't move it backwards. For overlapping matches, you need look around assertions:
my $string = '123perl456perl789perl10'; while ($string =~ /(?<=(..))perl(?=(..))/g) { print "$1perl$2\n"; }

Where (?<=...) means "is immediately preceded by", and (?=..) stands for "is immediately followed by". The look around assertions are not part of capturing (that's why you need to add capturing parentheses into the assertions), and they don't affect the position of the match.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-04-19 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found