0

I have a super screwed up data sets, with no real pattern, all I need from it is to find digit sequences from 3 to 7 digits, this is what I have been trying but matches.Count always gives 0

Function catchNumbers(inSt As String)

Dim regex As Object, str As String
Set regex = CreateObject("VBScript.RegExp")

With regex
  .Pattern = "\d{3-7}"
  .Global = True '
  .IgnoreCase = True
End With

inSt = Replace(inSt, ".", "")

Set matches = regex.Execute(inSt)

Debug.Print (matches.Count())

If matches.Count() > 0 Then
    For Each StrFound In matches
        Debug.Print (TypeName(StrFound) & " : " & StrFound)
        str = str & " " & StrFound
    Next StrFound
Else
    str = ""
End If

If Left(str, 1) = " " Then
    str = Right(str, Len(str) - 1)
End If

Debug.Print (str)

catchNumbers = str

End Function

Example of datasets :

25.802; 24.052/Guaiba 25.802; 24.052/Guaiba 25.859, L. 3-Ac, Fls.5; 25.862, L. 3-Ac, Fls. 6; 25.865, L. 3-Ac, Fls. 7; 25.856, L. 3-Ac, Fls. 4 25.859, L. 3-Ac, Fls.5; 25.862, L. 3-Ac, Fls. 6; 25.865, L. 3-Ac, Fls. 7; 25.856, L. 3-Ac, Fls. 4

3
  • Use comma instead of hyphen: \d{3,7} Commented Jun 9, 2016 at 21:25
  • This site is helpful to test your strings Commented Jun 9, 2016 at 21:31
  • I totally read the title as One Regex to rule them all, One Regex to find them, One Regex to bring them all, and in the darkness bind them ..okay maybe not. Commented Jun 9, 2016 at 21:39

1 Answer 1

2

Use comma instead of hyphen: \d{3,7}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.