regex question; $1, $2, etc

Hi,

If I have the following regex Pattern set up:

Pattern title = Pattern.compile("<title>([^<]+)</title>");

and I want what's within the parentheses to be stored as a varialbe, the way it would be in perl:

my $title = $1;

or whatever, how do I do that in java? Couldn't find it on any of hte regex tutorials I was looking at.

thanks,

bp

[431 byte] By [badpersona] at [2007-11-27 2:39:41]
# 1
Look at Matcher's find and group methods.
jverda at 2007-7-12 3:01:52 > top of Java-index,Java Essentials,New To Java...
# 2

The JDK regex package doesn't store captured groups in local variables like Perl does. Instead, you have to retrieve them from the Matcher using the group(int) methods. However, you can use $1, $2, etc. in the replacement string when you do a replaceAll or replaceFirst, and the Matcher will replace them with the appropriate captured groups.

uncle_alicea at 2007-7-12 3:01:52 > top of Java-index,Java Essentials,New To Java...