如何使用正则表达式获取以!
?
开头的单词,例如!Test
。
我尝试了这个,但是没有给出任何匹配:
@"\B\!\d+\b"
尽管当我用
!
替换$
时它确实起作用了。
最佳答案
这应该起作用:^!\ w +
MatchCollection matches = Regex.Matches (inputText, @"^!\w+");
foreach (Match match in matches)
{
Console.WriteLine (match.Value);
}
关于c# - C#正则表达式获取以开头的单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3952032/