简体   繁体   中英

How to match certain strings using regex regular expression

Given the following string:

string = @"
/SQL "\Geneva\GenevaAfterTaxExtracts" /SERVER SMAMSQL2602A /CHECKPOINTING OFF 
/SET "\Package.Variables[User::Portfolio].Properties[Value]";"2504,2505,2506,2507,336,339,340,343,344,345,346,348,349,350" 
/SET "\Package.Variables[User::FirstMonthEnd].Properties[Value]";"8/31/2013" 
/SET "\Package.Variables[User::LastMonthEnd].Properties[Value]";"8/31/2013" 
/SET "\Package.Variables[User::Files].Properties[Value]";"Valuations" /REPORTING E"

I would like to match and nextMatch as the following:

/SET "\Package.Variables[User::Portfolio].Properties[Value]";"2504,2505,2506,2507,336,339,340,343,344,345,346,348,349,350" 
/SET "\Package.Variables[User::FirstMonthEnd].Properties[Value]";"8/31/2013" 
/SET "\Package.Variables[User::LastMonthEnd].Properties[Value]";"8/31/2013" 
/SET "\Package.Variables[User::Files].Properties[Value]";"Valuations"

I'm using the following:

Regex re = new Regex(@"\/SET ([^\/]+)");
Match match = re.Match(command);

The first one and last one work fine, but the date ones get truncated before '/' as shown bellow

/SET "\Package.Variables[User::FirstMonthEnd].Properties[Value]";"8

/SET "\Package.Variables[User::LastMonthEnd].Properties[Value]";"8

How can I change Regex(@"/SET ([^/]+)") that way it matches on the dates as well?

Thanks in advance.

If they are separate lines

/SET.*

If they are on the same line

/SET.*?(?=/[a-zA-Z]+|$)

List<String> output=Regex.Matches(input,regex)
                         .Cast<Match>()
                         .Select(x=>x.Value)
                         .ToList();

这个正则表达式如何:

Regex re = new Regex(@"\/SET (.+?)(?=( *\/[a-z]| *$))");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM