Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression that rejects all input?

Tags:

regex

Is is possible to construct a regular expression that rejects all input strings?

like image 365
Kasper Avatar asked Sep 15 '08 12:09

Kasper


People also ask

What does '$' mean in regex?

$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.

What is difference [] and () in regex?

[] denotes a character class. () denotes a capturing group. [a-z0-9] -- One character that is in the range of a-z OR 0-9. (a-z0-9) -- Explicit capture of a-z0-9 .

What does (? I do in regex?

E.g. (? i-sm) turns on case insensitivity, and turns off both single-line mode and multi-line mode.


1 Answers

Probably this:

[^\w\W]

\w - word character (letter, digit, etc)
\W - opposite of \w

[^\w\W] - should always fail, because any character should belong to one of the character classes - \w or \W

Another snippets:

$.^

$ - assert position at the end of the string
^ - assert position at the start of the line
. - any char

(?#it's just a comment inside of empty regex)

Empty lookahead/behind should work:

(?<!)
like image 85
aku Avatar answered Sep 27 '22 21:09

aku