SOURCE

fntestSearchStr();

//测试fnsearchStr函数的
//fntestSearchStr();
function fntestSearchStr(){
    var t1 = "本期还款日为2019-10-23,还款金额235.11元,请保证";
    //t1 = "aaabbbcccdddeeefffggghhh";
    var t2 = "本期还款日为@,还款金额@元,请保证";
    t2 = "本期还款日为(\\S\*),还款金额(\\S\*)元,请保证";
    t2 = "本期还款日为@,还款金额@元,请保证";
    //t2 = "aaa(\\S\*)fff(\\S\*)hhh";

    t1 = '955951';
    t2 = '=95595';

    t1 = "本期还款日为2019-10-23,还款金额235.11元,请保证";
    t2 = "本期还款日为";

    var t3 = fnsearchStr(t1,t2);
    if (t3.length>0)
    {
        fnal('结果:'+t3);
    }
    else{
        fnal('结果:没找到')
    }
}
//用正则搜索字符串并返回结果数组,没找到返回空数组(length为0),
function fnsearchStr(tstr,truleStr){
	fnal('原始值:'+tstr);
    var t1 = truleStr;
    //如果条件有=,则是首尾匹配,要加^$
    if (t1.substr(0,1)=="="){
        t1 = "^" + t1.slice(1) + "$";
    }else{
        //否则就是模糊匹配,不改正则字符串
    }
    //替换要取出的值 @ 为正则匹配 (\S*)
    t1 = t1.replace(/@/gi,"\(\\S\*\)");

    fnal('正则字符串:'+t1);
	var trgExp = new RegExp(t1,"i");
//  var reg = eval("/" + t1 + "/i");
//  reg = /aaa(\S*)fff(\S*)hhh/i;
	var t2 = tstr.match(trgExp);
	return t2==null ? [] : t2;
}

//调试显示
function fnal(tstr){
    console.log(tstr);
}
console 命令行工具 X clear

                    
>
console