0

Though this is probably a duplicate, i haven't been able to make this work after reading similar questions. Looking for help please with this homework, i'm a newbie at programming.

I'm working on a program in C#. I have a text that contains for example this sentence: "My homework version V0.90 from". I need to extract "V0.90", and that may vary from anything between V0.90 to V2.00. It is always surrounded by "My homework version " and " from", i need to extract whatever is between that. This is what i've tried:

string RetRegMatch;
Match Match1 = Regex.Match(Friends[a], @"My homework version (.+) from", RegexOptions.IgnoreCase);
RetRegMatch = Match1.Value;

But i'm geeting as a result in Match1.Value this: "My homework version V0.90 from", and i only want the (+.) part to be in Match1.Value. That is, i would like to have in Match1.Value this: "V0.90". How can i do this?

Ashok
  • 743
  • 4
  • 13
hernanpare
  • 13
  • 4
  • https://regex101.com/r/zA2WCm/1 – Robert Harvey Apr 19 '19 at 15:42
  • If you just need to extract the version number, then there is no need to match the entire string, just search for the VX.XX pattern, if you are sure it always have the same format as in your example, then try something like `V[0-2]\.[0-9]+` Matches V, then any number between 0 and 2 followed by a . (dot) and one or more numeric values between 0 and 9. – MikNiller Apr 19 '19 at 15:43
  • I actually needed V0.99 to be surrounded by the text My homework version and from. The V0.99 may also be present in the rest of the text, that's why it was solved intead by Match1.Groups[1].Value. But thanks for the help! – hernanpare Apr 19 '19 at 15:49

1 Answers1

1

The part you need should be in the capture group (the part you put between ()). Try accessing it with

Match1.Groups[1].Value
Steven Fontanella
  • 764
  • 1
  • 4
  • 16