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
Post a Comment