Regex capturing group not working


I have a string like

I need to capture the “38”.

here is the assign:
Match = Regex.Match(“1-38”,“(?:\d+\s?-\s?)(.+)”)
but Match.Groups(0) returns 1-38 though when I test it in the configure regular expression, it does highlight 38 in yellow.

please help, thank you so much in advance

You can use simple split method @lynnsong986

varstring.split ("-"c)(1).tostring.trim

Cheers @lynnsong986

Hi @lynnsong986

If always length is 2 means you can use the below simply


Thank you.

Thanks to both, I’m asking the question because I want to know why that happens? I encountered similar problems with a lot more complicated text so I need to understand why.

The below one will help you to understand more about regular expression.

Thanks to @ppr

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