Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 537
Gill Bates Avatar asked Jan 02 '13 00:01

Gill Bates


2 Answers

Yes.

Here are a few examples.

.^
$.
(?!)

Naturally, there are an infinite number of such expressions.

like image 85
Kendall Frey Avatar answered Sep 22 '22 08:09

Kendall Frey


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

$x^
like image 43
mvp Avatar answered Sep 19 '22 08:09

mvp