Regex - Every spaces without back on line
I would like to 开发者_Go百科accept any spaces with [\s] between to words, but not returns on the line -> [^\n].
I'm using
([\w\-]+)([\s[^\n]])([\w\-]+)
but i doesn't work.
How can I do that?
A character class within another character class will not work. It would be better to specify what you want to match. So [ \t]+
which means one or more spaces or tabs
.
Two more points:
1. -
does not need to be escaped in a character class if it is the first or the last character, so [\w-]
or [-\w]
will work fine.
2. Unless you want to use the white space characters between the words you do not need to use brackets.
In summary, the following should work fine:
([-\w]+)[ \t]+([-\w]+)
try the following regex:
([\w\-]+)([\s^[\n]])([\w\-]+)
That should add the "not" you want for new lines.
cheers!
精彩评论