VBScript 中匹配多行, 并进行子操作的正则实例 /ASP VBScript Match Multiline/ By Stabx
VBScript 匹配多行其实很简单, 连 Multiline 也不用开. 但问题是, 匹配到内容后, 还要再对内容进行相关操作, 麻烦头疼就这么开始...
1. 简单匹配多行 2. 对匹配到的内容进行相关操作 注: 1 中的 Multiline 不须打开, 2 中的 Multiline 必须开启 提示: 1 中 没用 ?:, 2 中使用 ?:. (原因: 不用 ?: 表示储存变量值, 使用?: 表示不储存变量值) 提示1: 注意 2 中替换 Match 到 Str 的细节.
2. 对匹配到的内容进行相关操作 ------------------------------------------------- Set re1 = New regExp re1.Global = true re1.IgnoreCase = true re1.Multiline = true
re1.Pattern = "\[textarea\]([?:\s\S]+)\[\/textarea\]" Set Matches = re1.Execute(str) for each match in Matches match=replace(match,"<br/>",chr(13)) match=replace(match," ",chr(32)) match=replace(match,"<","<") match=replace(match,">",">") match=replace(match,"'","'") match=replace(match,""",chr(34)) match=replace(match,"[textarea]","<textarea name=""textarea"" cols=""60"" rows=""10"">",1,-1,1) match=replace(match,"[/textarea]","</textarea><br/><input type=""button"" onclick=""rc()"" value=""running code"" />",1,-1,1) re1.Pattern = "\[textarea\][\s\S]+\[\/textarea\]" str = re1.Replace(str,match) next set re1=nothing -------------------------------------------------
1. 简单匹配多行 ------------------------------------------------- Set re1 = New regExp re1.Global = true re1.IgnoreCase = true re1.Multiline = false re1.Pattern = "\[code\]([\s\S]+)\[\/code\]" str = re1.Replace(str,"$1") set re1=nothing ------------------------------------------------- | |