I have a string like this:
- blah blah blah_0123
So basically i need a regular expression to get those 4 numeric values after the _ delimiter. I’m sure it’s super simply but Regex looks like a foreign language to me!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That would be this regular expression:
(Capture group 1 holds the number.)
Or if your engine supports lookbehinds (which as far as I remember is not the case for C#):
(Capture group 0 holds the number.)
The
(...)denotes a catch group. In your match object you can then either access them by their index viayourMatch.Groups[index].Valueor if you named your catch groups via(?<name>...)by their name likeyourMatch.Groups[name].Value. The value will then hold whatever was matched by that particular group’s sub-expression (in your case the 4-digit number).Also if you only want the regex to match if those are exactly 4 numeric characters,
then replace the
+with{4}\bEdit: As Alan Moore correctly pointed out those are called “capture group”, not “catch group”. I need more sleep.