Recursive Regular Expressions

Hey everyone

I'm doing some string parsing at the moment - currently using java.util.regexp.

I need to parse a string with parentheses, and to to that, I need recursion.

Is there any way in Java to do recursive regular expressions?

(eg. like you can in PHP)

Thanks!

[303 byte] By [NightCabbagea] at [2007-11-27 4:16:04]
# 1
What do you mean by recursive regular expression? Can you post an example?
jsalonena at 2007-7-12 9:22:32 > top of Java-index,Java Essentials,Java Programming...
# 2

The OP is talking about the (?R) construct, which applies the entire regex recursively at the point where it appears, as in this example, which matches text with nested, balanced parentheses: (?:[^()]++|\((?R)\))*

There are also variations that recursively apply only the portion of a regex that appears in a specific (numbered or named) capturing group.

java.util.regex doesn't include that feature. The only Java regex package I know of that has anything like it is [url=http://www.javaregex.com/]stevesoft pat[/url].

uncle_alicea at 2007-7-12 9:22:32 > top of Java-index,Java Essentials,Java Programming...
# 3

****, uncle, i wish i had known that when i wrote this hack:

http://notetodogself.blogspot.com/2007/01/java-find-nested-balanced-tags.html

OP: i wrote the code above when i needed to parse out some nested DIV tags and didnt have time to figure out how to do it using an html parser lib.

you can copy/paste it out of my post to read it if you want.

it has some problems, but it works for most stuff.

mkoryaka at 2007-7-12 9:22:32 > top of Java-index,Java Essentials,Java Programming...