所以给出:
COLUMN_1,COLUMN_2,COLUMN_3,((COLUMN_1) AS SOME TEXT) AS COLUMN_4,COLUMN_5
我将如何获得我的比赛:
COLUMN_1 COLUMN_2 COLUMN_3 COLUMN_4 COLUMN_5
我试过了:
(?<!(\(.*?\)))(\w+)(,\s*\w+)*?
但我觉得我离开了基地:(我正在使用regexstorm.net进行测试.
感谢任何帮助:)
解决方法
你需要一个跟踪开括号和右括号的正则表达式,并确保只有一组平衡的括号(或根本没有括号)才匹配一个单词:
Regex regexObj = new Regex( @"\w+ # Match a word (?= # only if it's possible to match the following: (?> # Atomic group (used to avoid catastrophic backtracking): [^()]+ # Match any characters except parens | # or \( (?<DEPTH>) # a (,increasing the depth counter | # or \) (?<-DEPTH>) # a ),decreasing the depth counter )* # any number of times. (?(DEPTH)(?!)) # Then make sure the depth counter is zero again $ # at the end of the string. ) # (End of lookahead assertion)",RegexOptions.IgnorePatternWhitespace);
我试图提供一个regexstorm.net的测试链接,但它对StackOverflow来说太长了.显然,SO也不喜欢URL缩短器,所以我不能直接链接它,但你应该能够轻松地重新创建链接:http:// bit [dot] ly / 2cNZS0O