How to parse Json using Regex?

前端 未结 2 1372
你的背包
你的背包 2021-01-27 13:14

I want to parse this json data with regex. But, i could not. I tried like this module.getid(.*), but no working.

Only, I want to take this part -> mod

2条回答
  •  有刺的猬
    2021-01-27 14:02

    Well, to work from that new string you gave us:

    module.getid([{"id":"44423", "code":"mod_editor"}]);

    Here's a regular expression that nicely compartmentalizes all the data from the line provided

    m/module\x2egetid\x28\x5b\x7b\x22(?[^\x22]+)\x22\x3a\x22(?\d+)\x22\x2c\s+\x22(?[^\x22]+)\x22\x3a\x22(?[^\x22]+)\x22/

    You can reference the fields by using the named captures or the number of the capture, whichever you prefer.

    in this case to just return the portion of data which in this string is 44423 you could either reference capture number '2' or capture name 'value1'.

    I'm not sure which language you're using to 'parse' this data, so I couldn't give you an actual snippet of working code.

提交回复
热议问题