Reputation: 21182
So far so good, but I would like to match "Health and Beauty"
instead of "Health and Beauty _ _ _"
(trailing six spaces)
var a = Regex.Match("Health and Beauty 08/05/11 TO 08/11/11",
@"^(?<dept>.*)" +
@"(?<startdate>[0-9]{2}/[0-9]{2}/[0-9]{2})\s+TO\s+" +
@"(?<enddate>[0-9]{2}/[0-9]{2}/[0-9]{2})$").Dump();
I tried a negative look ahead, but .* continued to match everything.
@"^(?<dept>.*(?!(\s\s)))\s+" // should be "not followed by two spaces
I only have the option to match and extract, not to replace (the C# is for an example.)
Upvotes: 1
Views: 75
Reputation: 98776
Change @"^(?<dept>.*)"
to be non-greedy, and match on extra whitespace after:
@"^(?<dept>.*?)\s*"
Upvotes: 4