Home > other >  Regex to find words/number after a particular word
Regex to find words/number after a particular word

Time:01-23

My String: {“ID”:”NOKIA-71E1”,”KY”:”59ad728d99”,”U”:”admin”,”P”:”cfa522ec5a”,”S”:”FSH21290288A”,”23S”:”DC8D8A4171E1”,”N”:”5G12-13W-A”,”PN”:”3TG00799ABAA”,”IMEI”:”352778340662308”}

I need to get two outputs from the above string.

  1. The string after "s": which is FSH21290288A
  2. The string after "IMEI": which is 352778340662308

CodePudding user response:

(?<=[“”"]S[“”"]:[“”"])[^“”"]*(?=[“”"])
(?<=[“”"]IMEI[“”"]:[“”"])[^“”"]*(?=[“”"])

These experessions use lookahead and lookbehind groups, you can read more about them in this answer.

CodePudding user response:

Without knowing what tools you are using here to be more specific, this regex will return the strings you need in the capture groups \1 and \2. See regex101 example here.

"S":"(.*?)".*"IMEI":"(.*?)".*
  • Related