ASP正则截取字符串

2024-11-19 20:30:01
推荐回答(2个)
回答1:

'Str为要处理的数据
Dim Reg, reMatches
Set Reg = New RegExp
Reg.Pattern = "(距离[\s\S]+?) ([0-9\.]+公里)"
Reg.Global = True
Set reMatches = Reg.Execute(Str)
For Each reMatch In reMatches
Response.Write("字符串1:" & reMatch.subMatches(0))
Response.Write("字符串2:" & reMatch.subMatches(1))
Next
Set reMatches = Nothing
Set Reg = Nothing

回答2:

这么个思路:
1,先匹配出字符串2,正则部分:"\d{1,}(\.\d{1,})?公里"
2,使用匹配出的字符串2做为分隔符,split 取数组0,保存到字符串1

得到结果,字符串1和字符串2.