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.

    (a-d){3-5},(A-F){5-8},(0-6){8-9},[#$%^&+/]

    how to solve this using jquery or javascript.. ?




    Regards
    Nanda Kishore.CH
  • #765391
    Hi,
    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.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

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

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

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


Sign In to post your comments