Extracting text using regex

I want to extract “1234119006789:11+1234566789098:11” from below string using regex, or “1234119006789:11” and “1234566789098:11” separately.
ABC+DEFG:3+1234119006789:11+1234566789098:11+112345:1234+522++ORDERS’

Try this :

Imports System.Text.RegularExpressions

Module Module1

Sub Main()
    ' The input string.
    Dim value As String = "ABC+DEFG:3+1234119006789:11+1234566789098:11+112345:1234+522++ORDERS"

    ' Invoke the Match method.
    Dim m As Match = Regex.Match(value, _
                                 "\d{13}:\d{2}", _
                                 RegexOptions.IgnoreCase)

    ' If successful, write the group.
    If (m.Success) Then
        Dim key As String = m.Groups(1).Value
        Console.WriteLine(key)
    End If
End Sub

End Module

But there are no double quotes in the original text and multiple “+” are also there.

Can you share the Input here @aditit

ABC+DEFG:3+1234119006789:11+1234566789098:11+112345:1234+522++ORDERS’

Hi @aditit

Checkout this expression

System.Text.RegularExpressions.Regex.Matches("ABC+DEFG:3+1234119006789:11+1234566789098:11+112345:1234+522++ORDERS","\d{13}:\d+")

use For each to get all the matches like this

And if you know that the string will be only 2 means you can use this expression
For the first value

System.Text.RegularExpressions.Regex.Matches("ABC+DEFG:3+1234119006789:11+1234566789098:11+112345:1234+522++ORDERS","\d{13}:\d+")(0)

For the second value

System.Text.RegularExpressions.Regex.Matches("ABC+DEFG:3+1234119006789:11+1234566789098:11+112345:1234+522++ORDERS","\d{13}:\d+")(1)

Hope this Helps!

Regards
Sudharsan

Thank You. It worked.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.