C# Ending Regex statement
I have this code
Regex.Match(contents, @"Security=(?<Security>\D+)").Groups["Security"].Value;
this makes the following:
Security=SSPI;Database=Datab_ob
How do I make the Regex cut off at ; 开发者_如何学Pythonso i would only get Security=SSPI
Regex.Match(contents, "Security=(?<Security>[^;]+)").Groups["Security"].Value
How about this?
"Security=(?<Security>\D+?);"
you could to use a positive lookahead to look for the ; after your string, but not to match it. Using this:
Security=(?<Security>\w+(?=;))
as the regex pattern will get any words after the '=' and before the ';' into the Security named group
精彩评论