using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^.{0,1}(陪我一起)?听?你?(再|快|先)?能?(给我)?唱?(啊|一?个|吧|出来|一?首)?歌?(给我听|来听听)?(吧|啊|哇|呗|呀)?((好(么|嘛|吗))|好不好|小万|亲爱的|这么难)?.{0,1}$";
string input = @"你先唱给我听好吗
快唱啊
快唱啊你
你唱吧
你唱一个
唱一首吧亲爱的
再唱一首
你快唱吧
你能唱出来吗
唱出来
唱一个给我听呗好不好
快唱
唱
唱吧
你唱啊
唱一个嘛
唱一个啊
来听你唱歌
再给我唱一首呗
唱歌小万
你唱首歌给我听呗
陪我一起唱歌好吗
听你唱歌这么难
唱首歌来听听
你唱歌好好听啊再给我唱一首呗
我现在就很不开心你唱首歌给我听呗
会不会唱歌,唱首歌来听听";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx