Question: I have strings similar to the following:

```
 4123499-TESCO45-123
 every99999994_54

```

And I want to extract the largest numeric sequence in each string, respectively:

```
 4123499
 99999994

```

I have previously tried regex (I am using VB6) 

```
 Set rx = New RegExp
 rx.Pattern = "[^\d]"
 rx.Global = True

 StringText = rx.Replace(StringText, "")

```

Which gets me partway there, but it only removes the non-numeric values, and I end up with the first string looking like:

```
412349945123

```

Can I find a regex that will give me what I require, or will I have to try another method? Essentially, my pattern would have to be anything that isn't the longest numeric sequence. But I'm not actually sure if that is even a reasonable pattern. Could anyone with a better handle of regex tell me if I am going down a rabbit hole? I appreciate any help!

Answer: 
You cannot get the result by just a regex. You will have to extract all numeric chunks and get the longest one using other programming means. 

Here is an example:

```
Dim strPattern As String: strPattern = "\d+"
Dim str As String: str = "4123499-TESCO45-123"
Dim regEx As New RegExp
Dim matches  As MatchCollection
Dim match As Match
Dim result As String

With regEx
     .Global = True
     .MultiLine = False
     .IgnoreCase = False
     .Pattern = strPattern
End With

Set matches = regEx.Execute(str)
For Each m In matches
  If result < Len(m.Value) Then result = m.Value
Next

Debug.Print result

```

The `\d+` with `RegExp.Global=True` will find all digit chunks and then only the longest will be printed after all matches are processed in a loop.
That's not solvable with an RE on its own.

Instead you can simply walk along the string tracking the longest consecutive digit group:

```
For i = 1 To Len(StringText)
    If IsNumeric(Mid$(StringText, i, 1)) Then
        a = a & Mid$(StringText, i, 1)
    Else
        a = ""
    End If
    If Len(a) > Len(longest) Then longest = a
Next

MsgBox longest 

```

(first result wins a tie)