I want a regular expression that allows spaces between specific words. The regex below works great, but it doesn’t allow for spaces between words.
/\b(ADD|ADD CONSTRAINT|ALL|ALTER)(?=[^\w])/g
For example, when using this regular expression (ADD CONSTRAINT), only ADD is matched, the remaining CONSTRAINT does not matches.
It should match the both ADD CONSTRAINT including the space.
But don’t recommend to add CONSTRAINT separately, because it will match it separately and I don’t want this mess.
How can I tweak it to allow spaces?
Regex Example: https://regex101.com/r/FKphXU/1
>Solution :
You could add the second word as optional to your regex:
/\b(ADD(?: CONSTRAINT)?|ALL|ALTER)(?=[^\w])/g