我正在尝试替换BPM中表单中的所有特殊字符。
我用过
replace(/[_\W]+/g, "-")
但是这会替换所有包括。,()和空格。我需要排除其中一些字符被替换
这就是我想在BPM中做的事情
tw.local.sql =“插入BPM_RBD_GATEWAY值('Forwarded','”+ tw.local.RBDG.ProcessID +“','”+ tw.local.RBDG.SolID +“','”+ tw。 local.RBDG.BranchCode +“','”+ tw.local.RBDG.BranchName.replace(/ [_ \ W] + / g,“ - ”)+“','”+ tw.local.RBDG.Name_brwr。替换(/ [_ \ W] + / g,“ - ”)+“','”+ tw.local.RBDG.Name_Cooblgnt.replace(/ [_ \ W] + / g,“ - ”)+“' ,'“+ tw.local.RBDG.CustID_Exstng.replace(/ [_ \ W] + / g,” - “)+”','“+ tw.local.RBDG.D_Status_Loan.replace(/ [_ \ W ] + / g,“ - ”)+“','”+ tw.local.RBDG.D_Internl_Crdt_Ratng +“','”+ tw.local.RBDG.D_Scheme_ProdctType.replace(/ [_ \ W] + / g,“ - “)+”','“+ tw.local.RBDG.Acnt_Nmbr.replace(/ [_ \ W] + / g,” - “)+”','“+ tw.local.RBDG.Loan_Amnt.replace (/ [_ \ W] + / g,“ - ”)+“','”+ tw.local.RBDG.Bal_Outstandng.replace(/ [_ \ W] + / g,“ - ”)+“', '“+ tw.local.RBDG.Sanctnd_Period.replace(/ [_ \ W] + / g,” - “)+”','“+ tw.local.RBDG.Deviatns_loan_sanctnIfany.replace(/ [_ \ W] + / g,“ - ”)+“','”+ tw.local.RBDG.D_Loan_Sourcng +“','”+ tw.local.RBDG.Prevs_Rate_concsn.replace(/ [_ \ W] + / g,“ - “)+” ' ' “+ tw.local.RBDG.D_Existng_Accnt_Type +”','“+ tw.local.RBDG.Existing_ acnt_Rate.replace(/ [_ \ W] + / g,“ - ”)+“','”+ tw.local.RBDG.Recomndr_Rate.replace(/ [_ \ W] + / g,“ - ”)+ “','”+ tw.local.RBDG.Arrears_Inspctn_Comnts.replace(/ [_ \ W] + / g,“ - ”)+“','”+ tw.local.RBDG.D_Borwr_Source_Empl_Profsn.replace(/ [_ \ W] + / g,“ - ”)+“','”+ tw.local.RBDG.Borwr_Source_Details.replace(/ [_ \ W] + / g,“ - ”)+“','”+ tw .local.RBDG.Secrty_prmry_Nature.replace(/ [_ \ W] + / g,“ - ”)+“','”+ tw.local.RBDG.Secrty_prmry_Value.replace(/ [_ \ W] + / g, “ - ”)+“','”+ tw.local.RBDG.Secrty_prmry_DtlsLimit.replace(/ [_ \ W] + / g,“ - ”)+“','”+ tw.local.RBDG.Secrty_Collatrl_Nature。替换(/ [_ \ W] + / g,“ - ”)+“','”+ tw.local.RBDG.Secrty_Collatrl_Value.replace(/ [_ \ W] + / g,“ - ”)+“' ,'“+ tw.local.RBDG.Secrty_Collatrl_DetLimt.replace(/ [_ \ W] + / g,” - “)+”','“+ tw.local.RBDG.Deatils_ExistngBus_BrwrEnjoy.replace(/ [_ \ W ] + / g,“ - ”)+“','”+ tw.local.RBDG.Deatils_ExistngBus_TotGroup.replace(/ [_ \ W] + / g,“ - ”)+“','”+ tw.local .RBDG.Deatils_ExistngBus_OprtvAccnt.replace(/ [_ \ W] + / g,“ - ”)+“','”+ tw.local.RBDG.Deatils_ExistngBus_OtherPrdct.replace(/ [_ \ W] + / g,“ - “)+” ''“+ tw.local.RB DG.Additional_Details.replace(/ [_ \ W] + / g,“ - ”)+“','”+ tw.local.RBDG.Specific_BrRecom.replace(/ [_ \ W] + / g,“ - ” )+“”, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ' “+ tw.local.RBDG.Br_Entry_User +”', ' “+ tw.local.RBDG.Recomndr_Entry_User +”', '', '', '', '', '', '', '', '', ' “+ tw.local.RBDG.Date +”', '', '', '', '', '', '', '')“;
答案 0 :(得分:0)
使用replacer功能过滤掉您不想替换的匹配
var excludes = [",", " ", "(", ")"];
var output = input.replace(/[_\W]/g, function(match){
if ( excludes.indexOf(match) == -1 )
{
match = "-";
}
return match;
}) ;
<强>样本强>
var input = "asda<>*(*_()(), wdsf %^&%^&";
var excludes = [",", " ", "(", ")"];
var output = input.replace(/[_\W]/g, function(match){
if ( excludes.indexOf(match) == -1 )
{
match = "-";
}
return match;
}) ;
alert(output);
答案 1 :(得分:0)
var str = "ABC/D A.b.c.;Qwerty(dgdf)";
var result = str.replace(/[^A-Za-z.;()]/g, "");
你最终会得到ABCDA.b.c .; Qwerty(dgdf)
告诉我这是否适合你