这是我作为一天任务列表输入的用户输入示例
Meeting with developer 60min
Schedule a GoTo Meeting to discuss weekly sprint 45min
15min to code integration.
我们如何提取单词 60min、45min 和 15min 用于我的计算。
Regex.Match("Meeting with developer 60min", @"(\d+min)").Groups[1].ToString();
var output = input.Split(' ', '\n', '\r').Where(i => i.Contains("min"));
编辑处理换行符
试试看
string s = "Meeting with developer 60min "+
"Schedule a GoTo Meeting to discuss weekly sprint 45min "+
"15min to code integration.";
foreach (Match match in Regex.Matches(s, @"(?<!\w)60\w+"))
{
Console.WriteLine(match.Value);
}
foreach (Match match in Regex.Matches(s, @"(?<!\w)15\w+"))
{
Console.WriteLine(match.Value);
}
foreach (Match match in Regex.Matches(s, @"(?<!\w)45\w+"))
{
Console.WriteLine(match.Value);
}
或简而言之
var output = s.Split(' ').Where(i => i.Contains("min") || i.StartsWith("60") || i.StartsWith("15") || i.StartsWith("45"));
foreach (var o in output)
{
Console.WriteLine(o);
}