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.
我想知道如何在 C# 中使用正则表达式提取完整的单词
例如,我的字符串输入:
this$#23 is -kt jkdls
我想获得正则表达式匹配
This$#23
is-kt
jkdls
我需要提取非空格词[可以有数字或特殊字符]
通过指定正则表达式匹配模式
Regex myrex = new Regex("pattern")
MatchCollection matches = Regex.Matches("This$#23 is-kt jkdls", @"\S+"); foreach(Match match in matches) Console.WriteLine(match.Value);
Use \S+ to match words.
var words = string.Split(' ');