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

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -