I have a string, I just want to match string for any character except for space and new line. What must be regular expression for this?
I know regular expressions for anything but space i.e. [^ ]+
and regular expression for anything but new line [^n]+
(I’m on Windows). I am not able to figure how to club them together.
Advertisement
Answer
You can add the space character to your character class to be excluded.
^[^n ]*$
Regular expression
^ # the beginning of the string [^n ]* # any character except: 'n' (newline), ' ' (0 or more times) $ # before an optional n, and the end of the string