Adam Halasz
Adam Halasz

Reputation: 58301

Need a regex to match everything that does not contain a '?'

I want a regex with this rule: everything what not contains ?

I tried this but doesn't works:

^(?!\?)$

Upvotes: 1

Views: 159

Answers (2)

The Archetypal Paul
The Archetypal Paul

Reputation: 41759

 [^?]*

(zero or more not-?). You might need to escape the ? with a \ depending on your regex impementation. If your regex doesn't match agains the whole string by default, then

 ^[^?]*$

This will also match the empty string. If you don't want that, replace * with +

Upvotes: 2

codaddict
codaddict

Reputation: 455122

To match any string that does not have a ? in it you can use:

^[^?]*$

see it

You can also use a negative lookahead as:

^(?!.*\?).*$

See it

Upvotes: 3

Related Questions