Reputation: 77
I want to write regex that:
/scripts/my_app/
(/scripts/my_app/xxxx.sh
or /scripts/my_app/yyyyy/xxxz.sh
)/scripts/
(/scripts/another_string/xxxx.sh
or /scripts/some_string/yyyyy/xxxz.sh
)/xxxx/yyyy/zzzzz/qqqq.sh
or /aaaa/bbbb/ccc.sh
Something like this ^[(\/scripts\/my_app\/)|(?!\/scripts\/)].*
doesn't work.
Upvotes: 0
Views: 155
Reputation: 163352
You can use
^/(?:scripts/my_app/|(?!scripts/)).*
Explanation
^/
Start of string and match /
(?:
Non capture group
scripts/my_app/
Match literally|
Or(?!scripts/)
Negative lookahead, assert not scripts/
)
Close non capture group.*
Match 0+ times any characterAnother option is using a double negative lookahead
^/(?!scripts/(?!my_app/)).*
Upvotes: 1