正则表达式用于匹配特殊字符,没有空格或换行符

时间:2019-05-05 21:47:45

标签: c# regex regex-lookarounds regex-greedy

我有一个字符串,想要使用正则表达式来匹配所有字符,但不能有空格。

我尝试使用

替换所有空格
Regex.Replace(seller, @"[A-z](.+)", m => m.Groups[1].Value);

//rating
var betyg = Regex.Replace(seller, @"[A-z](.+)", m => m.Groups[1].Value);`

我希望

的输出
"Iris-presenter | 5"

但是,输出是

"Iris-presenter" 

在此demo中也看到过。

字符串是:

<spaces>Iris-presenter
<spaces>|
<spaces>5

2 个答案:

答案 0 :(得分:1)

我用margins rep78, pwcompare post matrix B = e(b_vs)' esttab matrix(B), collabels(none) ------------------------- B ------------------------- 2vs1.rep78 -.2187499 3vs1.rep78 -.034 4vs1.rep78 .2711112 5vs1.rep78 .3995455 3vs2.rep78 .18475 4vs2.rep78 .4898611 5vs2.rep78 .6182954 4vs3.rep78 .3051111 5vs3.rep78 .4335454 5vs4.rep78 .1284343 ------------------------- 来工作。这会删除所有here

中出现的空格和换行

答案 1 :(得分:0)

好问题!我不太确定,这是否是您想要的。 This expression但是与您的输入字符串匹配:

^((?!\s|\n).)*

enter image description here

该图显示了它如何工作:

enter image description here

编辑

根据revo的建议,该表达式可以大大简化,因为

  

^((?!\s|\n).)*等于^((?!\s).)*,并且都等于^\S*

enter image description here