I am using java for my program
suppose i have a string such as this
xx(yyzz(iijj))qq((kkll)(gghh))
Is there any way in which i could match xx(yyzz(iijj)) and qq((kkll)(gghh)) separately using a regex?
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.
You can match nested parenthesis using regex up to a fixed level. But more than 2 level will become rather messy (2 already is, to be frank). This will match your examples:
A quick explanation:
See the demo on ideone.com
There are regex flavors that can match an arbitrary number of nesting (Perl, .NET, PHP), but Java is not one of them.
But looking at the comment you posted under your question, I’d not handle this with regex, but a proper parser (be it a handcrafted one, or a generated).