C# 在以开头的同一行中查找多个正则表达式模式
我已经搜索了很多类似的问题来解决这个问题,但在Stackoverflow中找不到任何可以解决这个问题的帖子 我试图只在以“服务ID”开头的一行中查找模式的所有实例,但它也匹配其他行中的许多其他结果,我不想从任何其他地方包含这些结果 以下是输入文本:C# 在以开头的同一行中查找多个正则表达式模式,c#,regex,C#,Regex,我已经搜索了很多类似的问题来解决这个问题,但在Stackoverflow中找不到任何可以解决这个问题的帖子 我试图只在以“服务ID”开头的一行中查找模式的所有实例,但它也匹配其他行中的许多其他结果,我不想从任何其他地方包含这些结果 以下是输入文本: Dear Customer, Wxyz Communication is in receipt of maintenance activity. The details of maintenance activity are as below.
Dear Customer,
Wxyz Communication is in receipt of maintenance activity. The details of maintenance activity are as below. Your below mentioned service would experience an outage of “2 Hours” during the activity window.
Wxyz COMMUNICATIONS
Planned Work Notification
Ticket Reference - TCL CHGP1234567
Service ID 066BANGX1234567890, 066BANGX1234567891, A0B1C-D4E-FG5
NIMS ID A0ANX-T9Y-NP1, A0BC5-T1Y-NP1
Maintenance Type Emergency
Activity Status Scheduled
Execution Owner 3rd party service Provider
Location of activity Thailand
Activity Window (IST) 2020-09-07 23:30:00 IST to 2020-09-08 04:30:00 IST
Activity Window (GMT) 2020-09-07 18:00:00 GMT to 2020-09-07 23:00:00 GMT
Expected Impact Duration(DD:HH:MM) : 2 Hours
Activity Description Service provider will be performing an emergency software up gradation on their core router to improve the performance of service.
We request you to reschedule sensitive operations at your end accordingly.
We apologize for any inconvenience due to this event and resulting downtime.
If you have any queries with respect to this activity, feel free to contact us on the coordinates mentioned below:
Mail ID :planned.activity@Wxyzcommunications.com
Contact Number : + 91 20 1234 5678 & Toll Free no: 1-8001234567
We look forward to your co-operation and a long term synergic association.
Best Regards,
Customer Service
Wxyz COMMUNICATIONS
Ref:MSGTCL000027382595
以下是正则表达式:
(Service ID\s+,)*(?<CircuitID>[A-Z0-9]{11,30})
我在上有一份正则表达式副本,您可以将此正则表达式与
\G
一起用于您的比赛:
(?:^Service ID|(?!^)\G,)\h+(?<CircuitID>[A-Z0-9]{11,30})
(?:^服务ID |(?!^)\G,)\h+(?[A-Z0-9]{11,30})
正则表达式详细信息:
:匹配以(?:^服务ID |(?!^)\G,)
服务ID开头的行或上一个匹配的结尾
在前一个匹配的末尾或第一个匹配的字符串的开头断言位置,并且负前瞻\G
确保我们在行开始处不匹配(?!^)
\G
:匹配1+空格\h+
:在名为(?[A-Z0-9]{11,30})
的捕获组中匹配您的CircuitID
,即11到30个字母数字字符CircuitID
(?:^Service ID|(?!^)\G,)\h+(?<CircuitID>[A-Z0-9]{11,30})