I need to match a single character that is anything but a space but I don't know how to do that with regex.
Asked
Active
Viewed 1.7e+01k times
2 Answers
281
The following should suffice:
[^ ]
If you want to expand that to anything but white-space (line breaks, tabs, spaces, hard spaces):
[^\s]
or
\S # Note this is a CAPITAL 'S'!
![](../../users/profiles/4561887.webp)
Gabriel Staples
- 11,777
- 3
- 74
- 108
![](../../users/profiles/26210.webp)
Andrew Moore
- 87,539
- 30
- 158
- 173
136
\s
matches any white-space character\S
matches any non-white-space character- You can match a space character with just the space character;
[^ ]
matches anything but a space character.
Pick whichever is most appropriate.
![](../../users/profiles/18393.webp)
cletus
- 578,732
- 155
- 890
- 933