It's a slick regex, but you should be aware there's a problem running it with warnings:
#!/usr/bin/perl + use strict; use warnings; + my $str = "this is abc and bcf and xyz and ijklmn"; + while ($str =~ m{ ( # capture to $1 . # any character (?: # this chunk: $ # either the end of the + string | (??{ chr(1 + ord substr($&, -1)) }) # or the next character + (ASCII-wise) after # the one we just match +ed )+ # one or more times ) # end capture }xgs) { print "run: <$1>\n"; }
Produces:
(?: # this chunk: $ # either the end of the + string | (??{ chr(1 + ord substr($&, -1)) }) # or the next character + (ASCII-wise) after # the one we just match +ed )+ # one or more times matches null string many times in regex; marked by <-- HERE in m/ ( # capture to $1 . # any character (?: # this chunk: $ # either the end of the + string | (??{ chr(1 + ord substr($&, -1)) }) # or the next character + (ASCII-wise) after # the one we just match +ed )+ # one or more times <-- HERE ) # end capture / at ./x line 17. run: <hi> run: <abc> run: <bc> run: <xyz> run: <ijklmn>
In reply to Re^2: How to get Incremental charecter groups in a string
by liverpole
in thread How to get Incremental charecter groups in a string
by Dora
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |