Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在以开头的同一行中查找多个正则表达式模式_C#_Regex - Fatal编程技术网

C# 在以开头的同一行中查找多个正则表达式模式

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.

我已经搜索了很多类似的问题来解决这个问题,但在Stackoverflow中找不到任何可以解决这个问题的帖子

我试图只在以“服务ID”开头的一行中查找模式的所有实例,但它也匹配其他行中的许多其他结果,我不想从任何其他地方包含这些结果

以下是输入文本:

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
  • \h+
    :匹配1+空格
  • (?[A-Z0-9]{11,30})
    :在名为
    CircuitID
    的捕获组中匹配您的
    CircuitID
    ,即11到30个字母数字字符

试试这个正则表达式:棒极了。您提供的正则表达式正在按预期工作。你能解释一下这是如何实现的吗。
(?:^Service ID|(?!^)\G,)\h+(?<CircuitID>[A-Z0-9]{11,30})