Skip to content

Instantly share code, notes, and snippets.

@moritz
Created February 20, 2012 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moritz/1869161 to your computer and use it in GitHub Desktop.
Save moritz/1869161 to your computer and use it in GitHub Desktop.
Exhaustive regex matching
sub ex($str, &re) {
gather {
my $m := $str.match(&re);
if $m {
take $m;
take $m while $m := $m.CURSOR.'!cursor_next'().MATCH;
}
}
}
say ' ' x .from, .Str for ex('abracadabbra', rx/a.+a/);
abracadabbra
abracada
abraca
abra
acadabbra
acada
aca
adabbra
ada
abbra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment