content eg.
1. java.lang.String,
2. java.util.HashMap<Integer, Integer>,
3. java.util.ArrayList<Integer>,
4. java.util.HashMap<Integer, ArrayList<String>>,
5. java.util.HashMap<Integer, ArrayList<ArrayList<String>>>,

I need a regex for matching method parameters in Java.
I have tried with this one..
([a-zA-Z\. ]+,)|([a-zA-Z\. ]+<[a-zA-Z\., ]+(<[a-zA-Z\., ]+>)*>[ ]*,)

It is matching first 4 strings.
But it is not matching 5th one, since it is having nested <> combinations. (i.e. like <<<>>>)

How to make it to match 5th one also...
It should match all nested combinations of < & > to any depth...

Recommended Answers

All 2 Replies

See this thread for a concept that may help you

http://forums.sun.com/thread.jspa?threadID=5172164
then see the site referenced there (reproduced here)
http://www.javaregex.com/

Only Perl and PHP have builtin support for this so the only resources I can point you to to help with the concept are pages concerning those languages, such as this one
http://perldoc.perl.org/perlfaq6.html
more specifically
http://perldoc.perl.org/perlfaq6.html#Can-I-use-Perl-regular-expressions-to-match-balanced-text?

([a-zA-Z\. ]+,)|([a-zA-Z\. ]+<[a-zA-Z\., ]+(<[a-zA-Z\.,< ]+>)*>+[ ]*,)

Does that help?

Chris

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.