elefantsko
New Member
- Joined
- Feb 18, 2015
- Messages
- 3
Hi! I need some help with regex.. I'm trying to find a solution to extract a set of numbers from a long text. The text might look like:
"Blablabla bla bla blablabla 2 blabla bla 44 blablabla 1234567-0100 bla bla blabla"
What I need to extract from that text is "1234567-0100" (with the - ).
This is what i got:
but this returns everything before the set of numbers...
Anyone?
Regards!
"Blablabla bla bla blablabla 2 blabla bla 44 blablabla 1234567-0100 bla bla blabla"
What I need to extract from that text is "1234567-0100" (with the - ).
This is what i got:
Code:
Sub simpleRegex() Dim strPattern As String: strPattern = "[0-9]{7}\-[0-9]{4}"
Dim returnString As String: returnString = ""
Dim regEx As New RegExp
Dim strInput As String
Dim Myrange As Range
Set Myrange = ThisWorkbook.Worksheets(1).Range("A1")
If strPattern <> "" Then
strInput = Myrange.Value
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = strPattern
End With
If regEx.Test(strInput) Then
MsgBox (regEx.Replace(strInput, returnString))
Else
MsgBox ("Not matched")
End If
End If
End Sub
but this returns everything before the set of numbers...
Anyone?
Regards!