提取字下面是我通過用戶輸入的任務列表每天字符串:從一句
Meeting with developer 60min
Schedule a GoTo Meeting to discuss weekly sprint 45min
15min to code integration.
,我們怎麼能提取我計算的話60分鐘,45分鐘和15分鐘的輸入樣本。
提取字下面是我通過用戶輸入的任務列表每天字符串:從一句
Meeting with developer 60min
Schedule a GoTo Meeting to discuss weekly sprint 45min
15min to code integration.
,我們怎麼能提取我計算的話60分鐘,45分鐘和15分鐘的輸入樣本。
Regex.Match("Meeting with developer 60min", @"(\d+min)").Groups[1].ToString();
哦,這很簡單!這意味着什麼組[1]? –
它是括號內的值 - >(\ d + min)。所以你正在尋找的價值。 –
明白了..非常感謝你 –
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);
}
這是正則表達式的理想用例。 – Rotem