为大字符串定义正则表达式

本文关键字:正则表达式 定义 字符串 | 更新日期: 2023-09-27 18:21:28

我搜索过谷歌,仍然不知道如何为此编写正则表达式:

rec-1-20151103142759-d9fd57bc-4fe3-4b91-a640-ddd54ef081dd-Peakers-Andreea.Dumitru-ANDREAADUM-DSK-9fa377fe-3290-4cb7-9c7e-6ea86e01e08f-1066

我必须从这个字符串中获得以下内容:

  • id=1
  • 日期时间=20151103142759
  • Guidd2=d9fd57bc-4fe3-4b91-a640-ddd54ef081dd
  • type=扬声器
  • userName=Andreea.Dumitru
  • sourceName=ANDREEADUM-DSK
  • guidId2=9fa377fe-3290-4cb7-9c7e-6ea86e01e08f-1066

我已经开始使用

Regex regex = new Regex(-[0-9]{1}(| |-)[0-9]{14}(| |-)[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}(| |-)[a-fA-F](| |-)[a-fA-F](| |-) .... 

为大字符串定义正则表达式

这里有一个解决方案:

'w{3}-('d)-('d{14})-(['w'd]{8}-['w'd]{4}-['w'd]{4}-['w'd]{4}-['w'd]{12})-('w+)-(['w.]+)-('w+-'w+)-(['w'd]{8}-['w'd]{4}-['w'd]{4}-['w'd]{4}-['w'd]{12}-['w'd]{4})

这将是C#中没有regex选项的行:

Regex regex = new Regex(@"'w{3}-('d)-('d{14})-(['w'd]{8}-['w'd]{4}-['w'd]{4}-['w'd]{4}-['w'd]{12})-('w+)-(['w.]+)-('w+-'w+)-(['w'd]{8}-['w'd]{4}-['w'd]{4}-['w'd]{4}-['w'd]{12}-['w'd]{4})");

它在regex101中:https://regex101.com/r/bI8yH6/1