madridista
madridista

Reputation: 79

Incorporate regex quantifier into brackets

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

Answers (2)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626961

You can add this as a negative look-ahead at the beginning of the second pattern:

^(?!.*\*\*)([a-z]:)?(\\[^<>:"/\\|?;,$=%@~]+)+\\?$

See demo

Upvotes: 2

anubhava
anubhava

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

Related Questions