Reputation: 79
I am trying to incorporate the following negative lookahead regex
^(?!\*\*)
into the following regex
^([a-z]:)?(\\[^<>:"/\\|?;,$=%@~]+)+\\?$
Basically, I don't want two consecutive asterisks (**
) to appear anywhere in the file path. How do I modify the block [^<>:"/\\|?;,$=%@~]
to incorporate this condition? I tried using escape characters, but to no avail.
Upvotes: 0
Views: 61
Reputation: 626961
You can add this as a negative look-ahead at the beginning of the second pattern:
^(?!.*\*\*)([a-z]:)?(\\[^<>:"/\\|?;,$=%@~]+)+\\?$
See demo
Upvotes: 2
Reputation: 785316
I don't want two consecutive asterisk (
**
) to appear anywhere in the file path
Just prefix this negative lookahead before your regex:
/^(?!.*?\*\*)([a-z]:)?(\\[^<>:"/\\|?;,$=%@~]+)+\\?$/mg
(?!.*?\*\*)
after ^
will avoid matching the input if there are two *
in the input.
Upvotes: 1