4

I am new to this regular exp concept. I am trying to use this reg ex

[^@\s]+$

If i give the string as "abs", its actulally excluding the character 's' . which means '\s' is read as a character 's' rather than a whitespace. Please help me to solve this problem

vks
  • 67,027
  • 10
  • 91
  • 124
user3913114
  • 105
  • 3
  • 11

2 Answers2

5

You can use this POSIX equivalent:

^[^@[:space:]]+$

[:space:] matches any whitespace including newline. If you want to avoid matching newlines then use: [:blank:] instead.

anubhava
  • 761,203
  • 64
  • 569
  • 643
5

The space character class in POSIX is [:space:], so in your case, your regex would be:

[^@[:space:]]+$

Note that [:space:] can't standalone outside [] like \d or \s in other flavors. A space character class alone must be inside []:

[[:space:]]
nhahtdh
  • 55,989
  • 15
  • 126
  • 162