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# Regex 调用来查找放置在文本文件中的某些宏的所有实例:
MatchCollection matches = Regex.Matches(txt, @"/{macro:(.*?)}/");
但它每次都没有返回匹配项。txt 字符串看起来像这样:
嗨,我的名字是 {macro:name}
关于为什么这不起作用的任何快速观察?
@"\{macro:(.*?)\}"应该管用。
@"\{macro:(.*?)\}"
尝试转义{and }。这些是正则表达式中的特殊字符,用于表示特定的重复次数。所以试试这个:
{
}