Nanda Kishore
Nanda Kishore

Reputation: 1

How to remove character from inside a braces in jquery?

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

Answers (3)

Álvaro Touzón
Álvaro Touzón

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

Rakesh Lankapalli
Rakesh Lankapalli

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

Avinash Raj
Avinash Raj

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

Related Questions