oobe
oobe

Reputation: 458

How to write regular expression - contain substrings and not contain other substring

I nedd to check:
1) string contains "Canal" "Film"
2) string not contains "HD"

Canal+ Film 2 HD
Canal+ Film 2

This will check that string contains all substrings:

(?=.*Canal)(?=.*Film)

How to add to this regex pattern not contains condition?

Upvotes: 0

Views: 64

Answers (1)

Toto
Toto

Reputation: 91415

Use negative lookahead:

^(?=.*Canal)(?=.*Film)(?!.*HD)

Upvotes: 4

Related Questions