Reputation: 1654
I have been working with some sort of validation in which i need to make sure that the sum of digits in between two brackets is 100. I am using ! as my start delimeter and | as my ending delimeter.
** 90!(78!(50+50)|+22)|+10!(50 + 50)| + 20!(50 + 50 )|**
when i use !.+\|. this regular expression to replace the string It returns me the largest substring in between them. If i use !.+?\|. It returns me the smallest substring. What i need is largest in case of nested brackets and smallest in other case. A regular expression which should return me from the above expression
90 + 10 + 20
Upvotes: 0
Views: 57
Reputation: 114887
If you want to solve your problem using Regular Expression, then Balancing Groups are your answer.
But Given that the problem you're trying to solve doesn't really fit the problem domain of a Regular Expression, you'd probably be able to build a better solution using a parser/scanner.
Samples or scanner/parsers can be found easily. Some quick hits:
Upvotes: 1