[英]How can use custom regex in c#?
class Program
{
private static void showMatch(string text, string expr)
{
Console.WriteLine("The Expression: " + expr);
MatchCollection mc = Regex.Matches(text, expr);
foreach (Match m in mc)
{
Console.WriteLine(m);
}
}
static void Main(string[] args)
{
string str = "A Thousand Splendid Suns";
string pattern = @"[>][@\/" - &',.\w+ -]+[<]";
Console.WriteLine("Matching words that start with 'S': ");
showMatch(str, pattern);
Console.ReadKey();
}
}
string pattern = @"[>][@\/"" - &',.\w+ -]+[<]";
双引号会为您逃脱。 这条线现在有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.