This is what I am trying to remove strings from:
var myl = 'okok{"msg":"uc_okok"}'
and the results should be:
{"msg":"uc_okok"}
I have tried using regex
var news = myl.toString().replace(/ \{(.*""?)\}/g);
but it's not working? Any ideas?
How about using the following;
myl.toString().replace(/.*?({.*}).*/, "$1")
It should work with multiple layers of brackets as well;
str = 'okok{"msg":"uc_okok"}';
console.log(str.replace(/.*?({.*}).*/, "$1"));
str = 'adgadga{"okok":{"msg":"uc_okok"}}adfagad';
console.log(str.replace(/.*?({.*}).*/, "$1"));
Also you can simply extract the string between brackets as below;
var myl = "okok{\"msg\":\"uc_okok\"}okok";
var mylExtractedStr = myl.match('\{.*\}')[0];
console.log(mylExtractedStr);
I presume okok..
is a string
var d = 'okok{"msg":"uc_okok"}'
console.log(d.slice(d.indexOf('{'), d.lastIndexOf('}') + 1))
s = 'okok{"msg":"uc_okok"}';
s = '{' + s.split('{')[1].split('}')[0] + '}';
console.log(s);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With