开发者

regex not removing square brackets

i am using the following regex [^a-zA-Z\d!-] pattern in c# to clean special characters from filename so i can pull basic information from it and build initial class property values from it

how ever no matter wha开发者_如何学运维t i seem to do it wont clean the square brackets from the string according to regex builder it should be matching the square brackets but is not removing them when i run the replace operation

any help as to why would be greatly appreciated and a fix would be nice too =)

the code im using in c# is as follows:

var removeSpecChar = new Regex(@"[^a-zA-Z\d!-]");               

msa = msa.Substring(0, msa.Length - 4);
removeSpecChar.Replace(msa, " ").Trim();


Didn't try, but you really should escape the - in characher sets:

var removeSpecChar = new Regex(@"[^a-zA-Z\d!\-]"); 

Also note that \d is not equivalent to 0-9, it matches any unicode digit (including arabic digits etc.). So you may want to change that if this isn't your intention.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜