I need to extract a JSON string that sits inside a bigger string (I know, bad API response that I just have to deal with). Anyway I built a single regex to read everything inside {} and it works in all cases tested, except for the actual API response in the snippet below.
Any ideas why it's not working and how to make it work?
let dd = 'Error: Internal JSON-RPC error.\n{\n "code": 3,\n "message": "execution reverted: This limited season is sold out. Please wait for the next season.",\n "data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004154686973206c696d6974656420736561736f6e20697320736f6c64206f75742e20506c65617365207761697420666f7220746865206e65787420736561736f6e2e00000000000000000000000000000000000000000000000000000000000000"\n}';
alert(RegExp(/{.*}/).exec(dd))
RegExp()on a regular expression literal b) don't regex-match anything. Just split off the first line and treat the rest as JSON..does not match linebreaks.{is higher than the likelihood of it containing a linebreak. YMMV.