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.
Please, try.  

Pure VB. **No external libs or objects.**  

No brain-breaking regexp's patterns.  

No string manipulations, so - speed. **Superspeed. ~30 times faster** than [regexp](https://stackoverflow.com/a/49363651/6698332) :)  

Easy transform on variouse needs.  

For example, concatenate all digits from the source string to a single string. 

Moreover, if target string is only intermediate step,  

so it's possible to manipulate with numbers only.

```
Public Sub sb_BigNmb()
Dim sSrc$, sTgt$
Dim taSrc() As Byte, taTgt() As Byte, tLB As Byte, tUB As Byte
Dim s As Byte, t As Byte, tLenMin As Byte

    tLenMin = 4
    sSrc = "every99999994_54"

    sTgt = vbNullString

    taSrc = StrConv(sSrc, vbFromUnicode)
    tLB = LBound(taSrc)
    tUB = UBound(taSrc)

    ReDim taTgt(tLB To tUB)

    t = 0
    For s = tLB To tUB
        Select Case taSrc(s)
            Case 48 To 57
                taTgt(t) = taSrc(s)
                t = t + 1
            Case Else
                If CBool(t) Then Exit For   ' *** EXIT FOR ***
        End Select
    Next

    If (t > tLenMin) Then
        ReDim Preserve taTgt(tLB To (t - 1))
        sTgt = StrConv(taTgt, vbUnicode)
    End If

    Debug.Print "'" & sTgt & "'"
    Stop

End Sub

```

How to handle `sSrc = "ev_1_ery99999994_54"`, please, make by yourself :)
.