'Solve Catastrophic Backtracking in my regex
I am trying to detect names (French names) that can be in the following formats
CHARLES
CHARLES-ANTOINE
D'URENBURRY
CHARLES--ANTOINE
CHARLES ANTOINE
And for that I have the following regex
/^([A-Z]+(([-]{0,2}|[']|[ ])?[A-Z]+))+$/
Which works, but GitHub's code scanner shows this error
This part of the regular expression may cause exponential backtracking on strings containing many repetitions of 'AA'.
I understand the error, however, I'm not sure how to solve it.
My question is: how to solve it.
Thank you
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
