VBscript正则表达式中字符串匹配时间:2022-03-13 14:04:50 由于我对正则不是很清楚,我想求取把字符串 “str, DGK, rDJK, DJKl,DGK , end” 替换为 “str, MSN, rDJK, DJKl,MSN , end” 求匹配式的写法。 <SCRIPT LANGUAGE="VBScript"> <!-- Dim str,reg str= "str, DGK, rDGK, DGKl,DGK , end" Set reg=new RegExp reg.IgnoreCase=False reg.Global=True reg.Pattern="([\s|,])(DGK)([\s|,])" str=(reg.replace(str,"$1MSN$3")) Document.write(str) //--> </SCRIPT> <script language="vbscript"> dim stringExample stringExample = "str, DGK, rDGK, DGKl,DGK , end" Set re = New RegExp re.Pattern = "(\b)DGK(\b)" re.Global = True re.IgnoreCase = True re.MultiLine = True stringExample = re.Replace(stringExample,"$1MSN$2") alert stringExample </script> <script language="javascript"> var stringExample = "str, DGK, rDGK, DGKl,DGK , end"; var re = /(\b)DGK(\b)/gi; //这里的g就表示多次匹配,等同于VBSCRIPT的re.Global = True stringExample = stringExample.replace(re,"$1MSN$2"); alert(stringExample) </script> <script language="javascript"> var stringExample = "str, DGK, rDGK, DGKl,DGK , end"; var re = /(\b)DGK(\b)/gi stringExample = stringExample.replace(re,function(s,a,b){ alert([a,b]) }) </script>