这里我使用了下面提到的代码。用正则表达式分隔字符串并加上分号
MatchCollection matches = Regex.Matches(cellData, @"(^\[.*\]$|^\[.*\]_[0-9]*$)");
唯一的这种模式没有做的是它不会将分号和加号从主字符串中分离出来。
样本串
[dbServer];[ciDBNAME];[dbLogin];[dbPasswd] AND [[email protected]]_+[@IterationCount]
我想从字符串中提取
[dbServer]
[ciDBNAME]
[dbLogin]
[dbPasswd]
[[email protected]]
[@IterationCount]
。
你确定是这个模式的唯一的问题?请显示一些输入字符串和预期输出。 –
[dbServer]; [ciDBNAME]; [dbLogin]; [dbPasswd] AND [SIM_ErrorFound @ 1] _ + [@ IterationCount] 没有被分割。 –
你的意思是你只是想提取'[...]'子串?尝试像['@“\ [[^] [] +]”'](http://regexstorm.net/tester?p=%5c%5b%5b%5e%5d%5b%5d%2b%图5d与I =%5bdbServer%5D%3B%5bciDBNAME%5D%3B%5bdbLogin%5D%3B%5bdbPasswd%5D + AND +%5bSIM_ErrorFound%401%5d_%2B%5B%40IterationCount%5D)。 –