Find comma in quotes with regex and replace with HTML equiv

前端 未结 4 1493
终归单人心
终归单人心 2020-12-21 16:38

I\'m looking in a string such as:

\"Hello, Tim\"

Land of the free, and home of the brave

And I need it to become:

\"Hello&         


        
4条回答
  •  清酒与你
    2020-12-21 17:05

    With the above string as variable html you can use following code:

    var m = html.match(/"[\s\S]*"/);
    html = html.replace(m[0], m[0].replace(/,/g, ','));
    

    OUTPUT

    "Hello, Tim"
    
    Land of the free, and home of the brave
    

提交回复
热议问题