瞎写,仅供参考:1. 启动 Microsoft Visual Basic 6.0。 2. 在“文件”菜单上,单击“新建项目”。 3. 在“新建项目”对话框中,单击“Standard Exe”,然后单击“确定”。 默认情况下将创建 Form1。 4. 在“项目”菜单上单击“引用”。 5. 双击“Microsoft VBScript Regular Expressions 5.5”,然后单击“确定”。 6. 在工具箱中,双击“命令按钮”。 默认情况下,“Command1”将添加到窗体中。 7. 双击“Command1”以打开代码窗口。Private Sub Command1_Click() Dim re As RegExp, s As String, s1 As String s = "<a href=""http://www.google.com/viewthread.php?tid=a&fid=b""></a>"
Set re = New RegExp re.Pattern = "<a[^>]+href=""([^""]+)""[^>]*>(.*?)<\/a>"
If re.Test(s) Then '测试是否存在 s1 = re.Replace(s, "[url]$1$2[\url]") MsgBox s & vbNewLine & s1 End IfEnd Su
如:
dim lngI as long,strF as string
strF="$n2 = preg_replace('/<a[^>]+href="([^"]+)"[^>]*>(.*?)<\/a>/', '$2', $n2);"
lngI = InStr(1, strF, "$1")
debug.print Mid(strF, lngI, len("$1"))
你也可以编个函数专门处理一下
Dim a() As String
a = Split(Text1.Text, "&")
Debug.Print Split(a(0), "=")(1)
Debug.Print Split(a(1), "=")(1)
End Sub
可能我說得不清楚,我要的不是这个其实我是用来分析论坛帖子的,复制帖子內容而在帖子HTML码中,联接是 <a href="" ....... </a>的HTML代码
可是我要把每个联接转换为 bbs 码,如: http://www.google.com[url]google就如php中的preg_replace 函数而我要的是VB 代码
瞎写,仅供参考:1. 启动 Microsoft Visual Basic 6.0。
2. 在“文件”菜单上,单击“新建项目”。
3. 在“新建项目”对话框中,单击“Standard Exe”,然后单击“确定”。
默认情况下将创建 Form1。
4. 在“项目”菜单上单击“引用”。
5. 双击“Microsoft VBScript Regular Expressions 5.5”,然后单击“确定”。
6. 在工具箱中,双击“命令按钮”。
默认情况下,“Command1”将添加到窗体中。
7. 双击“Command1”以打开代码窗口。Private Sub Command1_Click()
Dim re As RegExp, s As String, s1 As String
s = "<a href=""http://www.google.com/viewthread.php?tid=a&fid=b""></a>"
Set re = New RegExp
re.Pattern = "<a[^>]+href=""([^""]+)""[^>]*>(.*?)<\/a>"
If re.Test(s) Then '测试是否存在
s1 = re.Replace(s, "[url]$1$2[\url]")
MsgBox s & vbNewLine & s1
End IfEnd Su