开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜