如何获取正则表达式中存在的字符串。
输入>:例如HtmlContent
包含字符串
"<% CustomerSignUpURL ||Text:Hello Abhishek %>"
:替换字符串后应该是锚标记,如下所示:
Hello Abhishek // where Hello Abhishek is anchor tag
请帮我写一下代码,下面给出的问号应该是什么:
campaignInfo.HtmlContent = campaignInfo.HtmlContent.replace(
/<% CustomerSignUpURL ||Text:([a-zA-Z0-9_-.]+) %>/g,
'<a href="<% CustomerSignUpURL %>">{????}</a>'
);
首先,通过:
获取标签的内容const tagContent = campaignInfo
.HtmlContent
.match(/CustomerSignUpURL ||(.*):(.*)%>/)[2];
// then replace it with:
campaignInfo.HtmlContent = campaignInfo.HtmlContent.replace(
/<% CustomerSignUpURL ||Text:.+?(?=>)./g,
`<a href="<% CustomerSignUpURL %>">${tagContent}</a>`
);