我有大量内容,如下所示:
<td width="20%"><a href="/search?tbs=shop:1&q=camping+lantern&sampleq=1">camping lantern</a></td>
<td width="20%"><a href="/search?tbs=shop:1&q=sandisk+cruzer&sampleq=1">sandisk cruzer</a></td>
<td width="20%"><a href="/search?tbs=shop:1&q=leaf+blower&sampleq=1">leaf blower</a></td>
<td width="20%"><a href="/search?tbs=shop:1&q=cd+rack&sampleq=1">cd rack</a></td>
<td width="20%"><a href="/search?tbs=shop:1&q=trackman+mouse&sampleq=1">trackman mouse</a></td>
我需要一些正则表达式来获取&sampleq=1">
和</a>
这是我自己做的正则表达式&sampleq=1"">(.*)<\/a>
而且它无法正常工作
答案 0 :(得分:1)
使用(.*?)
代替(.*)
并使用s修饰符,如果这是用于php,g修饰符,如果这是用于javascript
答案 1 :(得分:1)
使用此:
&sampleq=1\">(.*?)<\/a>
答案 2 :(得分:0)
似乎对我有用的最小可能似乎是1">.*</a
。
这是一个完整的VB.Net应用程序,用于测试它:
Module Module1
Const a As String = "<td width=""20%""><a href=""/search?tbs=shop:1&q=camping+lantern&sampleq=1"">camping lantern</a></td>" & vbNewLine & _
"<td width=""20%""><a href=""/search?tbs=shop:1&q=sandisk+cruzer&sampleq=1"">sandisk cruzer</a></td>" & vbNewLine & _
"<td width=""20%""><a href=""/search?tbs=shop:1&q=leaf+blower&sampleq=1"">leaf blower</a></td>" & vbNewLine & _
"<td width=""20%""><a href=""/search?tbs=shop:1&q=cd+rack&sampleq=1"">cd rack</a></td>" & vbNewLine & _
"<td width=""20%""><a href=""/search?tbs=shop:1&q=trackman+mouse&sampleq=1"">trackman mouse</a></td>"
Sub Main()
Dim r As New Text.RegularExpressions.Regex("1"">.*</a")
For Each m As Text.RegularExpressions.Match In r.Matches(a)
Console.WriteLine(m.Value.Replace("1"">", "").Replace("</a", ""))
Next
Console.ReadKey()
End Sub
End Module
答案 3 :(得分:0)