简体   繁体   中英

Regex - Every spaces without back on line

I would like to 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM