we want to use regex to validate a document structure. For this we simplify the document and the regex. The regex is generated out of a schema which is used for the validation. The application is completly client based and coded in JavaScript.
A simple example is this regex:
regex1 = new RegExp(/~(A{1}B?C?(D*|E*|F*|G*)+){1}~/g)
That means the document structure can have this structure
A
-B
-D
-D
-D
-D
-D
So the document structure is parsed to ~ABDDDDD~
Now I want to validate if I can add "A" to the end which would result in this string: ~ABDDDDDA~
This does not match with the reg ex anymore:
"~ABDDDDDA~".match(regex1)
This does work quiet fine, but the document structure can grow and be like this: ~ABDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD~
A matching value can be matched quiet fast, but if the value is then: ~ABDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDA~
It takes very long, most times I just close the browser and reopen it.
Does anyone have ideas how to solve it?
Thanks!
UPDATE
The RegEx should also cover more, the structure can be quiet dynamic. I have not used a RegEx Generator, this example is parsed from a self developed script and is just an example.
It is in this case, that there is one root element A, then optional B or C. And now in a not given order any amount of D,E,F,G. But at least one!
So it should be valid for: "~ABDDDDDFEG~" "~AGGGGGEGGD~" "~ABCDEFG~" "~ABCDDDDDDDDDDDDDDDEFGGGGGG~"
Additionally it is possible, that that the E is limited to 0-5 occurances.
As soon as I work with the match either(A | B), there are real performance issues in all browsers. (IE, Chrome, Firefox)
Any ideas? Are there any alternatives to "match either(A | B)" with better performance?