下面这个例子
class Program
{
static void Main(string[] args)
{
string pattern = @"\b\w+es\b";
Regex rgx = new Regex(pattern);
string sentence = "Who writes these notes?";
foreach (Match match in rgx.Matches(sentence))
{
Console.WriteLine("{0}--{1}", match.Value, match.Index);
}
Console.ReadKey();
}
}搜索以es结尾的,最后的输出结果是:
writes--4
notes--17我的问题是:
notes后面不是有一个问号吗?既然有?符号,怎么能说是以es结尾的呢?
谢谢!!
class Program
{
static void Main(string[] args)
{
string pattern = @"\b\w+es\b";
Regex rgx = new Regex(pattern);
string sentence = "Who writes these notes?";
foreach (Match match in rgx.Matches(sentence))
{
Console.WriteLine("{0}--{1}", match.Value, match.Index);
}
Console.ReadKey();
}
}搜索以es结尾的,最后的输出结果是:
writes--4
notes--17我的问题是:
notes后面不是有一个问号吗?既然有?符号,怎么能说是以es结尾的呢?
谢谢!!
正则基础之——\b 单词边界