截取字符串
如何截取字符串“xxxx <img xx> xxxx </img> xxxxxx <img xx> xxxx </img> ”
中 <img xx> XXX </img>
放入数组中。
[解决办法]
Dim doc As String = " " '需要验证的字符串
Dim f As New System.Text.RegularExpressions.Regex( " <img(? <body> [\s\S]*?) </img\> ")
Dim sum As Integer = f.Matches(doc).Count
Dim col As System.Text.RegularExpressions.MatchCollection = f.Matches(doc)
Dim temp(sum) As String
For i As Integer = 0 To col.Count - 1
temp(i) = col.Item(i).Groups(0).ToString
Next
[解决办法]
楼上的正则结果是没错。不过按你的意思,这样的正则更合适:
<img[^> ]*> (? <body> [\s\S]*?) </img\>
[解决办法]
我的办法,可能正则表达式不太对
MatchCollection rc=new Regex.Matches(@ " <img xx> [^ <> ]+ </img> ")
ArrayList al=new ArrayList();
foreach(Match m in mc)
{
al.Add(m.Value);
}