Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试删除字符串中任何非字母数字字符之前的字符。例如,假设您有一个名字“James Ebanks-Blake”,我可以使用以下方法将其拆分为一个数组:
var s = "James Ebanks-Blake".Split(' ');
即使有多个空格,它也只会创建更多的数组索引。所以我需要做的是遍历所有数组,找到带有特殊字符的索引,然后删除所有索引和特殊字符。
任何人都可以帮助我吗?
这在这里有效
[-^$#](.*)
只需在字符类中添加您认为的特殊字符
您想要的字符串将在第 1 组中
resultString = Regex.Match(subjectString, "[-^$#](.*)", RegexOptions.Singleline).Groups[1].Value;
[-'](.*)
那应该抓住 a-和 a之后的任何东西'。如果需要,可以在 [ ] 部分添加更多字符。只要确保逃避特殊的正则表达式。
-
'