Gill Bates
Gill Bates

Reputation: 15147

How to set up REGEX that doesn't match anything?

Just for curiosity.

Is it possible to create a regular expression that will not match any string, including an empty string?

Upvotes: 11

Views: 3165

Answers (3)

sirezekiel
sirezekiel

Reputation: 126

How about /^$x/. When I try it with ruby, it seems to work.

Upvotes: 0

mvp
mvp

Reputation: 116167

This regex should never match anything (provided you do not use single-line or multi-line modifiers):

$x^

Upvotes: 2

Kendall Frey
Kendall Frey

Reputation: 44326

Yes.

Here are a few examples.

.^
$.
(?!)

Naturally, there are an infinite number of such expressions.

Upvotes: 17

Related Questions