phdphd Posted December 11, 2015 Share Posted December 11, 2015 Hi All, I have a preg_match that checks if a string is made up of a number, or of a comma-separated list of numbers. The regex is : ^[0-9]+(,[0-9]+)*$ When the form is processed, the browser crashes if the string is very long. (It does not if I just do not run the preg_match). I guess the solution might be adjusting the pcre.backtrack_limit setting. However I would like to know if there is a better solution than the above preg_match to check the string. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/299701-regex-better-solution-than-0-90-9/ Share on other sites More sharing options...
Solution Jacques1 Posted December 11, 2015 Solution Share Posted December 11, 2015 Try possesive quantifiers: '/\\A\\d++(,\d++)*+\\z/' 1 Quote Link to comment https://forums.phpfreaks.com/topic/299701-regex-better-solution-than-0-90-9/#findComment-1527810 Share on other sites More sharing options...
phdphd Posted December 11, 2015 Author Share Posted December 11, 2015 The use of possessive quantifiers is indeed very efficient! Thanks for this great tip. Quote Link to comment https://forums.phpfreaks.com/topic/299701-regex-better-solution-than-0-90-9/#findComment-1527816 Share on other sites More sharing options...
.josh Posted July 31, 2016 Share Posted July 31, 2016 Just a random thought.. I don't know full context so this may or may not be something you can do, but I assume if it's a list of numbers you will split at the comma and loop anyways.. why not just simplify to ^[0-9,]+$ Quote Link to comment https://forums.phpfreaks.com/topic/299701-regex-better-solution-than-0-90-9/#findComment-1535356 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.