正则表达式在jquery或javascript中替换字符串,如下所述..

时间:2014-05-27 05:35:39

标签: jquery replace

jquery中的正则表达式替换字符串,如下所述。假设我有一个字符串,即

<#if ${x} == 'abc' > ${add} <#else if ${y} == 'dfg' > bef </#if>

在此,我要删除${}部分内的所有ifelse if。但不是在then部分,我怎样才能在jquery中进行呢?

1 个答案:

答案 0 :(得分:0)

var str="<#if ${x} == 'abc' > ${add} <#else if ${y} == 'dfg' > <#then ${y} == 'dfg' >";
var thenOut = str.split('then'); 
var required =thenOut[0].replace(/\$/g,"").replace(/\}/g,"").replace(/\{/g,"");
console.log(required+"then"+thenOut[1]);//heres what we need

继承人demo