Is there anyway to get a regex pattern to automatically stop searching after one match. I'd like to add regex searching to a web service I'm trying to create, but I don't want someone to be able to run a regex that would take a long time, just one match is good enough. Is this possible?
views:
266answers:
2
A:
The really bad degenerate pattern never match. And if you find a good way of finding the degenerate cases, well you will probably be due a lot of money. You are probably better off with a timeout. In Perl I would use alarm
combined with a block eval
.
You may also be looking for (*COMMIT) in Perl which prevents backtracking.
Chas. Owens
2009-05-26 18:24:37
+1
A:
You could still end up with a long running regex, even using a limiting quantifier.
Implementing an interruptable capability like this thread discusses is another option.
patjbs
2009-05-26 18:25:50