How to stop regex matching after 1 match without using non-living character

Anyway, to get a regex pattern to automatically stop the search after one match. I would like to add a regex search to a web service I am trying to create, but I don't want anyone to be able to run a regex that will take a long time, just one match is good enough. Is it possible?

+1


a source to share


2 answers


A really bad degenerate pattern never fits. And if you find a good way to find degenerative cases, then you are probably likely to make a lot of money . You will probably be better off with a timeout. In Perl I would use alarm

in conjunction with a block eval

.



You can also look for (* COMMIT) in Perl that prevents rollback.

0


a source


You can still use a long regex, even using a constraint quantifier.



Implementing an intermittent capability like this thread is discussing is another option.

+1


a source







All Articles