javascript - RegEx to match words in comma delimited list -


how can match text appears between delimiters, not match delimiters themselves?

text

donotfindme('donotfindme') donotfindme(findme) donotfindme(findme,findme) donotfindme(findme,findme,findme) 

script

text = text.replace(/[\(,]([a-za-z]*)[,\)]/g, function(item) {     return "'" + item + "'"; }); 

expected result

donotfindme('donotfindme') donotfindme('findme') donotfindme('findme','findme') donotfindme('findme','findme','findme') 

https://regex101.com/r/tb1ne2/1

here's pretty simple way it:

([a-za-z]+)(?=,|\)) 

this looks word succeeded either comma or close-parenthesis.

var s = "donotfindme('donotfindme')\ndonotfindme(findme)\ndonotfindme(findme,findme)\ndonotfindme(findme,findme,findme)";    var r = s.replace(/([a-za-z]+)(?=,|\))/g, "'$1'" );    alert(r);

used same test code other 2 answers; thanks!


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -