序列号的正则表达式

regular expression for a serial number

我有这么长的有效载荷,我需要从中 return 一个序列号,但它有很多序列号,我只想 return 某个标签后面的序列号。这是有效载荷:

USB:

USB 2.0 SuperSpeed Bus:

  Host Controller Location: Building

    Internal Card Reader:

      Product ID: 0x8406
      Serial Number: 000000000820 //i dont want this
      Building: Yes

USB 2.0 Bus:

  PCI ID: 0x8c31 


    iPhone:

      Vendor ID: 0x05ac  (skyway Inc.)
      Version: 7.02
      Serial Number: wea0aa752ada7722ac92575e98z2e89c691f4282 //i want this
      Speed: Up to 492 Mb/sec
      REC ID: 0x11100000 / 1

    skyway Internal Keyboard / Trackpad:

      Product ID: 0x0162
      Recog ID: 0x05ac  (skyway Inc.)
      Location ID: 0x14c00000 / 3
      Current Available (mA): 500
      Built-In: Yes

我如何构建一个正则表达式 return 只有以下内容:

wea0aa752ada7722ac92575e98z2e89c691f4282

我尝试执行以下操作,但这将 return 所有以序列号开头的表达式:

Serial Number: [0-9]

我只想要 iPhone 标题后显示的序列号。

使用捕获组。

"(?s)\biPhone:\n\n+(?:(?!\n\n).)+\bSerial Number: (\w+)"

DEMO

\biPhone:[\s\S]*?\bSerial Number: (\w+)

试试这个并获取群组 1.See 演示。

https://regex101.com/r/hF7zZ1/5

For Group

for (NSTextCheckingResult *match in matches) {
//NSRange matchRange = [match range];
NSRange matchRange = [match rangeAtIndex:1];
NSString *matchString = [htmlString substringWithRange:matchRange];
NSLog(@"%@", matchString);
}