Reputation: 1
i have data inside a square brackets. i need to remove character in side a braces.
ex:
(a-d){3-5},(A-F){5-8},(0-6){8-9},[#$%^&,+/]
as above example i need to remove comma(,) inside a square brackets.
i need output as below format.
(a-d){3-5},(A-F){5-8},(0-6){8-9},[#$%^&+/]
how to solve this using jquery or javascript.. ?
Regards Nanda Kishore.CH
Upvotes: 0
Views: 126
Reputation: 1230
Could you try to use string.replace, using reg exp like this
var str = '(a-d){3-5},(A-F){5-8},(0-6){8-9},[#$%^&,+/]';
str= str.replace(/\,(?![\s\S]*\,)/,"");
Delete last ocurrence of "," in your string expect it helps
Upvotes: 0
Reputation: 106
var word = '(a-d){3-5},(A-F){5-8},(0-6){8-9},[#$%^&,+/]';
alert(word.replace(/\[[^\]]*\]/g, function(x){return x.replace(/,/g, '')}))
Upvotes: -1
Reputation: 174706
Use str.replace
method.
var s = '(a-d){3-5},(A-F){5-8},(0-6){8-9},[#$%^&,+/]';
alert(s.replace(/\[[^\]]*\]/g, function(x){return x.replace(/,/g, '')}))
Upvotes: 2