Find comma in quotes with regex and replace with HTML equiv

前端 未结 4 1489
终归单人心
终归单人心 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:01

    result = subject.replace(/("[^"]+?),([^"]*?")/img, "$1,$2");

    This will work properly with your example, the only catch is it will not work if you have multiple , inside of the ". If you need it to work with multiple , inside of the " then take a look at this for a more complete way to parse CSV data with javascript.

提交回复
热议问题