TallChuck TallChuck - 1 year ago 80
Python Question

Python Regex that will work for any type of bracket

Is there a way to take a regular expression, such as


and make it correctly identify pairs of any type of bracket, like


without making incorrect matches, like

I'm specifically working with Python, but it should work similarly in any language.

Answer Source

No. Regular languages can't handle nesting correctly. You'll need a proper parser for that.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download