Following Regular expression ^[0-9A-Za-z]+(\s)*(-?(\s)*[0-9A-Za-z]+)*$ is matching for most of the cases like eg "dsffsd-fdsfds-dasda" but when i give string to be matched as "dsffsd-fdsfds-dasda-dasdas--dasdas-dsfs" im getting error in firebug saying Regular Expression Too Complex.
Any help would be appreciated, Thanks in advance
/xor(?x)so you can read it by adding spaces for breathing room and comments for explanation:^ [0-9A-Za-z]+ (\s)* ( -? (\s)* [0-9A-Za-z]+ ) * $. Plus I am pretty sure that that pattern is wrong: you have quantifiers around capture groups, like(\s)*for(\s*). Also,\wis much more readable than[0-9A-Za-z]. In most regex engines (but not Javascript’s, which is the absolute worst of all regex engines), it is also more correct, too. Remember that[A-Z]is a strong antipattern that’s always wrong sometimes.[A-Z]might work fine for a particular dataset and intent, there is always a different dataset where it fails to meet that same intention. Sometimes it works and sometimes it doesn’t. There is always a situation where it fails. So even if it seems to work in the here and now, that is only by accident and cannot be counted about. In the long run, therefore, it is always wrong, even if that always is only sometimes. See?