.net - Regular Expression Select text between spaces -
i need extract text between spaces within string. in sample below i'm looking extract text '401900 pre' group named recipe. group recipe must not return white space after letters pre. here's have @ moment. '401900 pre current user' gets printed screen. can't figure out how stop after pre.
the 401900 pre text changes regularly other text elements 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.
just include constant stuff don't want match in pattern:
@".*<operate mode> - (?'recipe'.*?)\s+current user"
note need make repetition inside group ungreedy, otherwise consume of spaces.
Comments
Post a Comment