简体   繁体   English

正则表达式 - 没有重新上线的每个空格

[英]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].我想接受单词之间带有 [\\s] 的任何空格,但不返回行 -> [^\\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 .所以[ \\t]+表示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. 1. -如果它是第一个或最后一个字符,则不需要在字符类中进行转义,因此[\\w-][-\\w]可以正常工作。
2. Unless you want to use the white space characters between the words you do not need to use brackets. 2. 除非您想在单词之间使用空格字符,否则您不需要使用括号。

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!干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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