Q:

Regular Expression Select text between spaces

I need to extract the text between spaces within a string. In the sample below I'm looking to extract the text '401900 PRE' into a group named Recipe. The group Recipe must not return any white space after the letters PRE. Here's what I have at the moment. '401900 PRE    Current User' gets printed to screen. I can't figure out how to stop after PRE. 
The 401900 PRE text changes regularly but the other text elements are constant. 
        string recipe = "<OPERATE MODE> - 401900 PRE    Current User";

        Regex regex = new Regex(@".*<OPERATE MODE> - (?'Recipe'.*\ *)");
        MatchCollection mc = regex.Matches(recipe);

        foreach (Match m in mc)
        {
            Console.WriteLine(m.Groups["Recipe"]);
        }

        Console.ReadLine();

Thanks. 

A:

Just include the constant stuff you don't want to match in the pattern:
@".*<OPERATE MODE> - (?'Recipe'.*?)\s+Current User"

Note that you need to make the repetition inside the group ungreedy, otherwise it will consume some of the spaces.

