【壹百分】求正则,获取<form>中action属性,在线等。
本人VB.NET新手,还不会用正则表达式,最好写个完整的希望高手们写个完整的范例。还有,HTML代码里可能会出现action和Action的区别,以及多余的空格,谢谢大家!
[解决办法]
<form[^> ]+action\s*=\s* "?([^ " ']+) "?[^> ]*>
调用时注意指定IgoreCase
[解决办法]
楼上正解: <form[^> ]+action\s*=\s* "?([^ " ']+) "?[^> ]*>
[解决办法]
查找:
Dim str As String = " " ' 这里放你要处理的HTML
Dim regex1 As New System.Text.RegularExpressions.Regex( " <form[^> ]+action\s*=\s* " "?([^ " " ']+) " "?[^> ]*> ", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
Dim mat As System.Text.RegularExpressions.Match = regex1.Match(str)
Do
If mat Is Nothing Then
Exit Do
End If
Dim Action As String = mat.Groups(1).Value
'处理……
mat = mat.NextMatch '取下一个
Loop
替换:
Dim str As String = " " ' 这里放你要处理的HTML
Dim regex1 As New System.Text.RegularExpressions.Regex( " <form[^> ]+action\s*=\s* " "?([^ " " ']+) " "?[^> ]*> ", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
str = regex1.Replace(str, AddressOf proc)
Private Function proc(ByVal m As System.Text.RegularExpressions.Match) As String
Dim action As String = " " '换成要替换成的Action
Return m.Value.Replace(m.Groups(1).Value, action)
End Function