How to Modify string Inside character, Javascript Regex -
how modify:
var = ' z ok z '; = a.replace(/z(.*)z/, function(match){ return match.trim().touppercase();}); console.log(a); // output: " z ok z "
i expect " zthis okz ";
the uppercase work, trim function ignored
you matching spaces (*)
. change to:
var = ' z ok z '; // here, you'll notice added spaces next "z" character. = a.replace(/z (.*?) z/, " z$1z ").touppercase(); console.log(a); // output: " zthis okz "
what match between "z", , rewrites "z" directly next it.
Comments
Post a Comment