You must Sign In to post a response.
  • Category: JQuery

    How to remove character from inside a braces in jquery ?

    Hi team,
    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.


    how to solve this using jquery or javascript.. ?

    Nanda Kishore.CH
  • #765391
    Please try following:
    var str = "(a-d){3-5},(A-F){5-8},(0-6){8-9},[#$%^&,+/]";
    var res = str.substring(str.indexOf("[")+1, str.indexOf("]"));
    alert("String to be replaced: " + res)
    var res2= res.replace(/,/g , "")
    alert("Replaced string: "+res2);
    alert("Final result: " +str.replace(res,res2));
    Hope it helps.
    Shashikant Gurav

  • #765396
    I have not test this code, but you can use this. following code is the regular expression in javascript

    a = a.replace(/\[.*?,\]/g, '');
    a = a.replace(/\[[^,\]]+\]/g, '');
    look below snippet
    function myFunction()
    var str = "(a-d){3-5},(A-F){5-8},(0-6){8-9},[#$%^&,+/]";
    str = str .replace(/\[[^,\]]+\]/g, '');
    hope it helps

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • Sign In to post your comments