I have a JSON string that looks like {\"heading\":\"Test\",\"id\":1} and I want to wipe the ID data from the string.
I’ve tried test.gsub(/\,\\"id\\"\:d+/, '') but that’s not working.
How best to achieve this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Sergio’s JSON.parse is something you should consider. But baring that, those
\‘s you are seeing probably aren’t really part of the string. That’s just how irb is displaying it.So
test.gsub(/,"id":\d+/, '')should be what you want. (Also fixed a few other small bugs in the regex).