regex - How do I count inside of a javascript regular expression? -


how stick counter in javascript regular expression substitution?

the question answered here perl/pcres.

i've tried obvious string.replace(/from/g, "to "+(++count)), no (the ++count evaluated once @ start of string.replace, seems).

you can pass along function called per match replace:

// callback takes match first parameter , groups // additional, left empty because i'm not using them in function. string.replace(/from/g, function() {   return "to " + (++count); }); 

i've found extremely handy tool in replacing complex string portions (like user comments embedded codes) on client side ease burden bit on server.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -