用asp实现的截取指定格式字符串的代码
程序员文章站
2022-04-14 20:26:05
有段字符串: asdfasdlfajsodf{#kljlkkm#}ojgvjfkdsf{#wdfs#}llsdflksdf 没任何规律的...我要把里...
有段字符串: asdfasdlfajsodf{#kljlkkm#}ojgvjfkdsf{#wdfs#}llsdflksdf
没任何规律的...我要把里面的{#kljlkkm#}和{#wdfs#}查找出来...
1、split办法:
<%
dim i, scode, acode, snewcode
scode = "asdfasdlfajsodf{#kljlkkm#}ojgvjfkdsf{#wdfs#}llsdflksdf"
acode = split(scode, "{#")
snewcode = ""
for i = 0 to ubound(acode)
if instr(acode(i), "#}") > 0 then snewcode = snewcode & "{#" & split(acode(i), "#}")(0) & "#}"
next
response.write snewcode
%>
2、正则办法:
<%
dim scode, snewcode, otempreg, match, matches
scode = "asdfasdlfajsodf{#kljlkkm#}ojgvjfkdsf{#wdfs#}llsdflksdf"
set tempreg = new regexp
with tempreg
.ignorecase = true
.global = true
.pattern = "\{\#.+?\#\}"
set matches = .execute(scode)
for each match in matches
snewcode = snewcode & match.value
next
end with
set tempreg = nothing
response.write snewcode
%>
没任何规律的...我要把里面的{#kljlkkm#}和{#wdfs#}查找出来...
1、split办法:
复制代码 代码如下:
<%
dim i, scode, acode, snewcode
scode = "asdfasdlfajsodf{#kljlkkm#}ojgvjfkdsf{#wdfs#}llsdflksdf"
acode = split(scode, "{#")
snewcode = ""
for i = 0 to ubound(acode)
if instr(acode(i), "#}") > 0 then snewcode = snewcode & "{#" & split(acode(i), "#}")(0) & "#}"
next
response.write snewcode
%>
2、正则办法:
复制代码 代码如下:
<%
dim scode, snewcode, otempreg, match, matches
scode = "asdfasdlfajsodf{#kljlkkm#}ojgvjfkdsf{#wdfs#}llsdflksdf"
set tempreg = new regexp
with tempreg
.ignorecase = true
.global = true
.pattern = "\{\#.+?\#\}"
set matches = .execute(scode)
for each match in matches
snewcode = snewcode & match.value
next
end with
set tempreg = nothing
response.write snewcode
%>
上一篇: ASPWebPack 代码 提供下载