I'm trying to extract string between two characters. First charachter has multiple occurences and I need the last occurence of first character. I've already checked similar questions but all suggested regexes don't work in case of multiple occurences of first character.
Example:
TEST-[1111]-20190603-25_TEST17083
My code:
string input = "TEST-[1111]-20190603-25_TEST17083";
var matches = Regex.Matches(input,@"(?<=-)(.+?)(?=_)");
var match = matches.OfType<Match>().FirstOrDefault();
var value = match.Groups[0].Value;
The current result:
[1111]-20190603-25
Expected result:
25
.*to consume the initial part?(?<=-)([0-9]+)(?=_)? If we can guarantee that exepected result is a number;(?<=-)([^\-]+?)(?=_).matches any char. If you know there must be no other-in between-and_use[^-]instead of the dot.