Friday, 15 July 2011

c# - Replace multi minus to one minus by regex -



c# - Replace multi minus to one minus by regex -

there string

str = "test--removing-----minus-";

trying replace by

str = regex.replace(str, @"\-*", @"-");

but get

"t-e-s-t--r-e-m-o-v-i-n-g--m-i-n-u-s-";

* matches 0 or more match of previous pattern. utilize {2,} match 2 or more match.

and - not needed escaped.

str = regex.replace(str, @"-{2,}", @"-");

c# regex replace

No comments:

Post a Comment