1

I have this long payload and I need to return a serial number from it but it has many serial numbers and I only want to return the serial number after a certain tag. Here is the payload:

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

How can I build a regular expression that will return to me only the following:

wea0aa752ada7722ac92575e98z2e89c691f4282

I tried doing the following but that will return all expressions that start with serial number:

Serial Number: [0-9]

I just want the serial number that shows up after the iPhone title.

j2emanue
  • 60,549
  • 65
  • 286
  • 456

2 Answers2

1

Use Capturing group.

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

DEMO

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
1
\\biPhone:[\\s\\S]*?\\bSerial Number: (\\w+)

Try this and grab the group 1.See demo.

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);
}
Community
  • 1
  • 1
vks
  • 67,027
  • 10
  • 91
  • 124
  • awesome but is there anyway to grab the first group from the regular expression itself. – j2emanue Jul 22 '15 at 18:11
  • @j2emanue there is only one group present.. dont know much about this language :( – vks Jul 22 '15 at 18:13
  • @vks not needed why? `(?:(?!\\n\\n).)+` asserts that there isn't any empty line present inbetween. But's you'rs fails in that case. So this would match the string `Serial NUmber` from the paragraph which exists next to the iphone. – Avinash Raj Jul 22 '15 at 18:43
  • @AvinashRaj its simply not required....OP just wants serial number after iphone..... dats it...you are making it overcomplicated!!!!!!The format seems pretty fixed to me – vks Jul 22 '15 at 18:44