user222427
user222427

Reputation:

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 ; so i would only get Security=SSPI

Upvotes: 1

Views: 97

Answers (3)

Sam Holder
Sam Holder

Reputation: 32936

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

Upvotes: 0

brysseldorf
brysseldorf

Reputation: 211

How about this?

 "Security=(?<Security>\D+?);"

Upvotes: 0

yu_sha
yu_sha

Reputation: 4410

Regex.Match(contents, "Security=(?<Security>[^;]+)").Groups["Security"].Value

Upvotes: 3

Related Questions