I have a string like this: (((foo)))
I would like to get an object from the string like this: {"text":"foo", "brackets" : 3}
How is it possible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It isn’t necessarily the best solution, but a regular expression to match multiple
(with(\(+), followed by everything up to)with([^)]+), followed by multiple)with(\)+)is pretty easy. This will allow you to validate that the parentheses are balanced before you build your object.All of this can also be done with string maipulation, but the regex code may be clearer to read.