我需要在c#中使用以下正则表达式的帮助。我有一个给定的字符串,我试图选择这样的文本。该字符串来自发票。剩余的物品将是购买的物品。快速正则表达式的句子
510258-350-JDX 84008043942000 Confirmation of Order is mandatory.994007029908500 ItemMaterial NumberDescription64008029908500Order 840780-16742500
Long text *** Text*** ==> 84008043942000 Confirmation of Order is mandatory.994007029908500
ItemMaterial NumberDescription64008029908500Order 840780-16742500
510258-350JDFT8 84008043942000 Confirmation of Order is mandatory.994007029908500ItemMaterial NumberDescription94008029908500Order 840080-16742500 Long text 232 *** Text*** ==> 84008043942000 Confirmation of Order is mandatory.994007029908500
ItemMaterial NumberDescription64008029908500Order 840080-16742500
但我目前的方式是行不通的。我想选择这些并从字符串中删除它们。示例中的数字可以更改。
string r2 = raa.Replace(r1, "");
string rgconfirm ="";
string rgorder ="";
if (r2.Contains("Confirmation")) {
rgconfirm = Regex.Match(r2, @"(\d{14} Confirmation)").Groups[0].Value;
if (r2.Contains("-")) {
rgorder = Regex.Match(r2, @"(Order \d{6}-*+\d{8})").Groups[0].Value;
}
}
string check1 = rgconfirm + "(.*?)" + rgorder;
var toreplace = Regex.Match(r2, check1).Groups[0].Value;
if (toreplace.Length > 2) {
r2 = r2.Replace(toreplace, "");
}
请准确指定您要查找的输出。 –
请注意,组[0]是整个比赛。组[1]是第一个捕获组。 [源:](https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.match.groups(v = vs.110).aspx)“GroupCollection对象的第一个元素(元素在索引0处)包含一个匹配整个正则表达式模式的字符串,每个后续元素,从索引1向上,表示一个捕获组“ – Quantic
带有预期输出的示例输入和输出将会有帮助。 –