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.
JavaScript
x
2
1
^[^n ]*$
2
Regular expression
JavaScript
1
4
1
^ # the beginning of the string
2
[^n ]* # any character except: 'n' (newline), ' ' (0 or more times)
3
$ # before an optional n, and the end of the string
4