I have one string
var tStr="[[[{"Name":"A","No":"8000444284"}],{"Name":"B","No":"8485990983"}],{"Name":"C","No":"0000000000"}]";
In this string i try to remove all [
and ]
My Code is:
function trim(str, characters)
{
var c_array = characters.split('');
var result = '';
for (var i=0; i < characters.length; i++)
result += '\\' + c_array[i];
return str.replace(new RegExp('^[' + result + ']+|['+ result +']+$', 'g'), '');
}
And this Function Use as
trim(str,'[ ]');
In Calling var tStr="[[[{"Name":"A","No":"8000444284"}],{"Name":"B","No":"8485990983"}],{"Name":"C","No":"0000000000"}]";
thats not working please any one help me...:)
\[|\]
Try this.Replace by empty string
.See demo.
https://www.regex101.com/r/fG5pZ8/4
var re = /\[|\]/g;
var str = '[[[{"Name":"A","No":"8000444284"}],{"Name":"B","No":"8485990983"}],{"Name":"C","No":"0000000000"}]';
var subst = '';
var result = str.replace(re, subst);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.