in reply to Re^7: Understanding a portion of perlretut
in thread Understanding a portion on the Perlretut
how does $dna =~ / (\w\w\w)*? TGA /gx differ logically from $s =~ / (f)*? C /gxThe important difference here is the length of $1.
After the first match (A is where the matching started, B denotes the position of the capture group)
XXXxxxTGAxxTGAxxxxTGAxx ^ ^ | | A B
the matching starts at B + 1. Zero times \w\w\w doesn't match here, we have xxTGAx, so the engine tries longer and longer strings, until it finds the TGA:
XXXxxxTGAxxTGAxxxxTGAxx ^ ^ | | A B
The next search will start at B + 1 again, and fail on xx.
But, with the capture group of length 1, you always match the nearest group, because the (f)*? tries longer and longer strings. Maybe what's confusing here is that expanding the group by one character is similar to the engine advancing the starting position after a match failure?
($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,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Understanding a portion of perlretut
by Athanasius (Archbishop) on Dec 10, 2015 at 12:46 UTC | |
by choroba (Cardinal) on Dec 10, 2015 at 13:02 UTC | |
by Athanasius (Archbishop) on Dec 10, 2015 at 13:27 UTC | |
by Corion (Patriarch) on Dec 10, 2015 at 13:30 UTC |