Tag Archives: Perl Backtracking regx

Backtracking example1

Let’s say you want to find the word following “foo” in the string “Food is on the foo table.”: #!/usr/bin/perl # Example of backtracking algorithm use 5.006; use strict; use warnings; $_ = “Food is on the foo table.”; if ( /b(foo)s+(w+)/i ) { print “$2 follows $1.n”; } When the match runs, the first… Read More »