Регулярные выражения - VB
Формулировка задачи:
В поле TextBox вводится адрес сайта, программа должна выводить название сайта (Например: адрес сайта -http://www.cyberforum.ru/newthread.php?do=newthread&f=29, название сайта - cyberforum или http://100formul.ru/matem., название сайта 100formul).
Помогите реализовать данную программу с использованием регулярных выражений в VB.
Решение задачи: «Регулярные выражения»
textual
Листинг программы
Option Explicit
Private Sub Form_Load()
Dim oRegEx As Object
Dim oMatches As Object
Dim oSubmatches As Object
Dim i As Long
Dim sText As String
Set oRegEx = CreateObject("VBScript.RegExp")
oRegEx.IgnoreCase = True
oRegEx.Global = False
sText = "http://www.cyberforum.ru/newthread.php?do=newthread&f=29"
oRegEx.Pattern = "^([url]http://|https://)?(www(2)?\.)?([/url][^/]*)?(\..*?)(/|$|\?)"
'oRegEx.Pattern = "(?!.*(Пушкин|Пятачок)).*(Антуан|Экзюпери)|^(хром)$"
Set oMatches = oRegEx.Execute(sText)
If oMatches.Count = 0 Then Exit Sub
Set oSubmatches = oMatches(0).Submatches
If oSubmatches.Count >= 3 Then
Debug.Print oSubmatches(3)
End If
' 'Test
' For i = 0 To oMatches.Count - 1
' Debug.Print i + 1 & " - " & oMatches(i)
' Next
'
' Debug.Print "Submatches:"
'
' For i = 0 To oSubmatches.Count - 1
' Debug.Print i + 1 & " - " & oSubmatches(i)
' Next
End
End Sub