Replace with Regex

by Mohammed Fellak

JavaScript

const regex = /<custom-url href='([\S\s]*?)'[^>]*>([\S\s]*?)<\/custom-url>/gim;
str = `I agree to the <custom-url href='http://www.unify.com/uk/Home/Internet/web/uk/misc/tac/privacy_policy.aspx?tac=1'>Data Privacy Policy</custom-url> and the <custom-url href='http://www.unify.com/uk/Home/Internet/web/uk/misc/tac/use_policy.aspx?tac=1'>Acceptable Use Policy</custom-url>.`;
let m;

//var newStr = str.replace(regex, replacer);
var newStr = str.replace(regex, '<a href="$1">$2<\/a>');
console.log(newStr);
function replacer(match, p1, p2) {
	return '<a href="'+p1+'">'+p2+'<\/a>';
}