Say that I have a string which contains both multiple sets and nesting of parenthesis. I want to extract only the string in the first parenthesis encountered, including whatever nested parenthesis it contains.
For example:
this (is(maybe)) a test (and maybe not)
I want to extract:
is(maybe)
I believe this can be accomplished without the use of regexes, by which I can easily do it.
So my question is how can this be accomplished without regexes?
Pseudo code:
Lest pseudo code be the only answer I've taken it upon myself to answer this using standard algorithms. Given
const string foo{ "this (is(maybe)) a test (and maybe not)" }
c++14 can be used to solve like this:From here, if both
start
andfinish
are notcend(foo)
the string is valid and can be obtained fromstring(next(start), finish)
(Live Example).It's possible that this is as good a solution as there is in C++. I guess it is just wishful thinking that there's something out there to match parentheses and find the value.