Say I have the following:
This path could be anything, we basically want to get the
jQuery is not necessary here; Javascript supports regular expressions on its own, so jQuery is not part of the answer.
Javascript's regex replace function is simply called .replace()
, and is a method on the string class. You would use it as follows:
var mystring = 'this is a string';
mystring.replace(/is a/,'might be a');
//mystring is now equal to 'this might be a string'.
That should be enough to get you started. Since you referenced preg_replace()
in the question, I assume you already know how to use regular expressions well enough not to need a detailed discussion of how to solve your specific example.