Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something like PHP's preg_replace_callback() in javascript?

What I want to do is str.replace(pattern, callback),

not simply str.replace(pattern, replace_pattern),

is it possible to do it in javascript?

like image 300
wamp Avatar asked Jun 04 '10 03:06

wamp


1 Answers

Why, yes, you can do exactly that: str.replace(pattern, function () { ... }).

Here's some documentation: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/replace

like image 53
deceze Avatar answered Sep 28 '22 07:09

deceze