c# - Regex split on parentheses getting double results -


im taking string "4 + 5 + ( 7 - 9 ) + 8" , trying split on parentheses list containing 4 + 5, (7-9), + 8. im using regex string below. giving me 4 + 5, (7-9), 7-9 , + 8. hoping easy. thanks.

 list<string> test = regex.split("4 + 5 + ( 7 - 9 ) + 8", @"(\(([^)]+)\))").tolist(); 

remove set of parenthesis have in regex:

(\(([^)]+)\)) // regex (           ) // outer parens  \(       \)  // literal parens match    (     )    // parens don't need     [^)]+     // 1 or more 'not right parens' 

the parens create match 'inside literal parens', 7 - 9 see.

so should have:

@"(\([^)]+\))" 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -