使用正则匹配方法比较方便!
asp就内置支持一个"正则表达式"对象, 看下面的例子
<%
Set regEx = New RegExp ' 建立正则表达式对象。
regEx.Pattern = "\[tncboy].+\[/tncboy]" ' 设置匹配模式。
regEx.IgnoreCase = true ' 设置是否区分字符大小写。
set Matches = regEx.Execute("hello! [tncboy]my name is [/tncboy], do you kown me") ' 匹配字符串
for each matchstr in Matches
response.write matchstr.value&"<br>" '输出结果
next
%>
而你只要修改匹配模式串:
"\[a].+\[/a]" 即可做到
如果改为
"\[.+].+\[.+]"
可匹配到所有的[..][/..]组合,当然如果一个
字符串含多个组合,将会取最外层嵌套