Karai17
Karai17

Reputation: 943

Do not match string if it contains a specific word

I've been at this problem for a while now, and every website on earth tells me the same answer which doesn't seem to be working.

I am trying to match any string as long as the string data: is not present at the beginning. Ultimately I am trying to stop people from injecting data URIs into my parser. The best pattern I've come up with so far is:

((?!data:).*)

But it doesn't actually work. At all.

https://regex101.com/r/oR3iD8/2

Upvotes: 0

Views: 40

Answers (1)

Lucas Trzesniewski
Lucas Trzesniewski

Reputation: 51330

Sure, the simplest "pattern", would be...

data:

Heh, if this matches, you discard the string. If it doesnt't match, you take the full input string. Why even use regexes, a simple "string contains" function will do.

If you really want a regex solution, use a lookahead:

(?s)\A(?!.*?data:).*

But really, why bother?

Upvotes: 2

Related Questions