How to match any non white space character except a particular one?

Lazer picture Lazer · May 25, 2011 · Viewed 203.1k times · Source

In Perl \S matches any non-whitespace character.

How can I match any non-whitespace character except a backslash \?

Answer

Tim Pietzcker picture Tim Pietzcker · May 25, 2011

You can use a character class:

/[^\s\\]/

matches anything that is not a whitespace character nor a \. Here's another example:

[abc] means "match a, b or c"; [^abc] means "match any character except a, b or c".