能用正则式提取字符串中匹配的子字符串吗?
例如:
Dim Str AS String = "ABCDEFG{BB(12)}HIJKL"
Dim Reg AS new Regex("\{BB\(([\d])\)\}", RegexOptions.IgnoreCase)
Str=Reg.Replace(Str,"$1")'Str=ABCEFG12HIJKL我需要能直接提取到"$1"值的方法.
例如:
Dim Str AS String = "ABCDEFG{BB(12)}HIJKL"
Dim Reg AS new Regex("\{BB\(([\d])\)\}", RegexOptions.IgnoreCase)
Str=Reg.Replace(Str,"$1")'Str=ABCEFG12HIJKL我需要能直接提取到"$1"值的方法.
直接提取,还要这干嘛?
估计应该对你有用
http://blog.csdn.net/xuxiaoping_cumt/archive/2005/11/19/532892.aspx
Dim Reg AS new Regex("\{BB\(([\d])\)\}", RegexOptions.IgnoreCase)dim mc as MatchCollection = Reg.Matches(Str)dim strs(mc.Count - 1) as stringfor i as integer = 0 to mc.Count - 1
strs(i) = mc(i).Value
nextStr=Reg.Replace(Str,"$1")