A way to not include something in a regex capture group
1 answer
You need to use a capture group:
var input = "test <123>";
var results = Regex.Matches(input, "<(.*?)>")
.Cast<Match>()
.Select(m => m.Groups[1].Value)
.ToList();
m.Groups[1].Value allows you to get the value of capture group # 1.
And the best, more effective regular expression can be <([^>]*)>(it matches <, then matches and fixes in Group 1 any zero or more characters other than >, and then just matches >). See regex demo :
+4
