Last active
June 25, 2018 15:02
-
-
Save tst32/e9283d8f9bee6e25eee0cc25149364da to your computer and use it in GitHub Desktop.
vb with regex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
XXXA XXXB XXXC | |
172.28.16.0/23 1 | |
10.57.0.0/26 1 | |
192.168.1.0/24 1 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub NewRegex() | |
' | |
Dim para As Paragraph | |
Dim text As Variant | |
Dim wordtext As Variant | |
Dim sPath As String | |
Dim sFile As String | |
Dim oWord As Word.Application | |
Dim oDoc As Word.Document | |
Dim RegexPattern As String | |
Dim re As New RegExp | |
Dim Matches As Variant | |
Dim I, x, cnt As Long | |
cnt = Range("a2", Range("a2").End(xlDown)).Rows.Count 'СТОЛБЕЦ C ПОДСЕТКАМИ | |
'TODO цикл по строке 2 | |
Set oWord = CreateObject("Word.Application") | |
sPath = CreateObject("WScript.Shell") _ | |
.specialfolders("Desktop") & "\" & "test" | |
If Right(sPath, 1) <> "\" Then sPath = sPath & "\" | |
sFile = Dir(sPath & "*" & "XXXA" & "*.docx") | |
'https://regex101.com/r/VHSSbJ/2 | |
RegexPattern = "((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.)){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\/(3[0-2]|(1|2)?[0-9]))?" | |
Set oDoc = oWord.Documents.Open(sPath & sFile) | |
With re | |
.Global = True | |
.MultiLine = True | |
.IgnoreCase = False | |
.Pattern = RegexPattern | |
End With | |
For Each para In oDoc.Paragraphs | |
wordtext = wordtext & para.Range.text | |
Next para | |
Set Matches = re.Execute(wordtext) | |
Debug.Print Matches.Count | |
For x = 2 To cnt + 1 'ОСНОВНОЙ ЦИКЛ ПО СТОЛБЦУ | |
text = Cells(x, 1).Value | |
For I = 0 To Matches.Count - 1 | |
If text Like Matches(I) Then | |
Debug.Print ("YES+ "), text | |
Cells(x, 2).Value = "1" 'ЕСТЬ ПОДСЕТЬ СТАВИМ 1 | |
End If | |
Next I | |
Next x | |
End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ID XXXA | |
Назначение сети Октеты | |
tinao.mskobr.ru 172.28.16.0/23 | |
asus.router 192.168.1.0/24 | |
mgts.ru 10.57.0.0/26 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment