Regular expression: find spaces (tabs/space) but not newlines

As Eiríkr Útlendi noted, the accepted solution only considers two white space characters: the horizontal tab (U+0009), and a breaking space (U+0020). It does not consider other white space characters such as non-breaking spaces (which happen to be in the text I am trying to deal with).

A more complete white space character listing is included on Wikipedia and also referenced in the linked Perl answer. A simple C# solution that accounts for these other characters can be built using character class subtraction:

[\s-[\r\n]]

Or, including Eiríkr Útlendi's solution, you get

[\s\u3000-[\r\n]]

Try this character set:

[ \t]

This does only match a space or a tabulator.


Use character classes: [ \t]

Tags:

Regex