Have a text
hjgv ygkuy (1) erg erg ewr (2)erg erg erg er. (3)
want to get 1,2,3 and if there is only one then just 1
i have tried with (\d)\)
i get matches but i want the result like
1,2,3
if just one then just that digit 1
Have a text
hjgv ygkuy (1) erg erg ewr (2)erg erg erg er. (3)
want to get 1,2,3 and if there is only one then just 1
i have tried with (\d)\)
i get matches but i want the result like
1,2,3
if just one then just that digit 1
You may use a simple \(([0-9]+)\)
regex that matches any (
followed with 1 or more digits and then a )
, while capturing the digits into Group 1.
See a VB.NET demo:
Dim res As MatchCollection = Regex.Matches("hjgv ygkuy (1) erg erg ewr (12)erg erg erg er. (321)", "\(([0-9]+)\)")
If res.Count() > 0 Then
For Each m As Match In res
Console.WriteLine(m.Groups(1).Value)
Next
End If
Output:
1
12
321
Pattern details:
\(
- a literal (
([0-9]+)
- Capturing group 1 matching one or more ASCII digits (as \d
in a .NET regex may match more than just 0-9
)\)
- a literal )
.