I'm opening this thread that is really similar to another one but I cannot figure out an issue : I have an input field that allow a alphanumeric string with an optional unique space as a separator, then an optional other alphanumeric string etc.... I find this regex :
^([0-9a-zA-z]+ ?)*$
It works ! But the performance is really bad as soon as I have 2 consecutives spaces in a long sentence and those 2 spaces are located far in the sentence. In the example below, the result is ok in a half of second if I put the 2 spaces at the beginning of the sentence. But it lasts 10 seconds or more if located far.
dzdff5464zdiophjazdioj ttttttttt zoddzdffdziophjazdioj ttttttttt zoddzdffdzdff ttttt zoddzdfff ttttt zoddzdfff ttttt zoddzdfff ttttt zoddzdfff ttttt zoddzdfff ttttt zoddzdfff ttttt zoddzdfff ttttt zoddzdfff ttttt zo999 ddzdfff ttttt zoddzdfff ttttt zoddzdff
The 2 spaces are after the 999
.
Do you have any idea or suggestion to improve this regex ?
Thanks and regards
PF
ps: you can check the issue as soon as you enter an invalid character far in the string, not specifically 2 spaces.
EDIT : another example : 12345678901234567890' ==> 20 char. + 1 invalid char. => result is immediate Add 5 valid char. and it lasts 5 seconds to perform the regex ! 1234567890123456789012345'