2

The following regular expression matches the character a:

"a"

The following regular expression matches all characters except a:

"[^a]"

The following regular expression matches a ton of characters:

"."

How do I match everything that is not matched by "."? I can't use the same technique as above:

"[^.]"

because inside the brackets, the . changes meaning and only stands for the character . itself :(

fredoverflow
  • 246,999
  • 92
  • 370
  • 646

2 Answers2

3

The below negative lookahead will work.

(?:(?!.)[\S\s])

Java regex would be,

"(?:(?!.)[\\S\\s])"

DEMO

The idea behind the above regex is, it would match only \r or \n or \t or \f that is the characters which aren't matched by a dot (Multiline mode).

Avinash Raj
  • 166,785
  • 24
  • 204
  • 249
  • Match the character from the list `\S` or `\s` if it's not matched by a dot. So it will end up with `\r` or `\n` or `\t` or `\f` – Avinash Raj Oct 03 '14 at 18:33
0
"[^\\.]"

use double backslash for regex used character. for example

\\.\\]\\[\\-\\)\\(\\?
tsogtgerel.ts
  • 905
  • 1
  • 13
  • 29