我有类似的字符串:
坦帕(TAMPA)总部-亨德森路(Henderson Rd)9125号-评论发布在工作订单#7065
TAMPA HQ-亨德森路9125号-工单#79651警报
TAMPA HQ-9125 Henderson Rd-工作单#805923请求号已分配
在C#中是否有提取WO#的通用方法?,因此输出为:
工单#7065
工作单号79651
工作单#805923
等吗?
答案 0 :(得分:3)
此正则表达式可以使用:Regex r = new Regex("Work Order # \d+");
Match match = r.Match("TAMPA HQ - 9125 Henderson Rd - Work Order # 79651 Alert");
。
{{1}}
答案 1 :(得分:0)
使用这样的正则表达式:
"^Work Order #.\d+"
答案 2 :(得分:0)
这是一种算法:
LengthOfString = StrLength (IncomingString)
WorkOrderNumberPosition = FindInString (IncomingString, "Work Order # ")
LeftSideRemovedString = SubString (IncomingString, WorkOrderNumberPosition, LengthOfString - WorkOrderNumberPosition)
WorkOrderRemoved = Replace (LeftSideRemovedString, "Work Order #", "")
现在,遍历并找到最后一个连续的字符,即数字,并使用该数字做一个子字符串。
答案 3 :(得分:0)
//to simulate an input lines
var input = new StringBuilder();
input.AppendLine("TAMPA HQ -9125 Henderson Rd -Comment Posted on Work Order # 7065");
input.AppendLine("TAMPA HQ -9125 Henderson Rd -Work Order # 79651 Alert");
input.AppendLine("TAMPA HQ - 9125 Henderson Rd -Work Order # 805923 Request Number Assigned");
Regex regex = new Regex(@"(?<Identifier>Work Order # \d+)");
var results = regex.Matches(input.ToString());
foreach (Match match in results)
{
Console.WriteLine(match.Groups["Identifier"].Value);
}
在这里进行了测试:http://rextester.com/CAR42027