对于 C#,试试这个:
var list = new string[] {
"Help", "Help # 7256", "Help # 83930",
"ph # 7222", "this is a test example",
"Help # 029299", "New # 92929",
"Help # 7256 8945", "Help # 83930 8998 787989"
};
// bear in mind that the $ at the end matches only these strings
// if you want it to match something like Help # 1284 12841 0933 SUBJECT HERE"
// then remove the $ from the end of this pattern
const string pattern = @"^(Help)\s#\s(\d{3,6})\s?(\d{3,6})?\s?(\d{3,6})?$";
var regex = new Regex(pattern);
foreach (string s in list)
{
if (regex.Match(s).Success)
Console.WriteLine(s);
}
Console.WriteLine("Done.");
Console.ReadKey();
输出:
Help # 7256
Help # 83930
Help # 029299
Help # 7256 8945
Help # 83930 8998 787989