in reply to Re^2: Did regex match fail because of "end of string"?
in thread Did regex match fail because of "end of string"?
Is there a reason that you cannot simply keep starting from the same location until you receive an end-of-string, or find a match? Can this be more data than you want to hold?
If you can't do this, I can think of one (very ugly) option. Something like this:
You will also have to special-case lines terminated with '\'.sub example { $foo = "[&#\$]"; $regex = "a\\d+[ars]{2,4}(aa|ab|ac)"; $string="wle;fnaekf;fla;lkcnovnifa "; $min = $regex."\$"."foo"; if ($min !~ /\$$/) { $min .= '$'; } $match = 0; $tot = length($string); $index = $tot; print "index is $index\n"; while (1) { print "min is $min\n"; eval { if ($string =~ m/$min/g) { $index = pos $string; $match = 1; } }; # print "err is $@\n"; last if $match; $min =~ s/..$//; last if $min eq ""; if ($min !~ /\$$/) { $min .= '$'; } } return $index; } $ind = example();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Did regex match fail because of "end of string"?
by moritz (Cardinal) on Oct 17, 2007 at 05:45 UTC | |
by Illuminatus (Curate) on Oct 17, 2007 at 08:08 UTC | |
by moritz (Cardinal) on Oct 17, 2007 at 11:35 UTC |