This library is a thin wrapper for java.util.regex
, implementing named capture groups for Java 5/6 (and it works on Android).
This is a fork of the named-regexp project from Google Code (currently inactive).
You can use the same constructs for named capture groups from Java 7 (i.e., (?<name>patt)
, etc.), as in the following example:
import com.google.code.regexp.Pattern;
import com.google.code.regexp.Matcher;
public class NamedRegexpTest {
public static void main(String[] args) {
// pattern contains capture group, named "foo"
Matcher m = Pattern.compile("(?<foo>\\w+) world").matcher("hello world!");
m.find();
System.out.println(m.group("foo")); // prints "hello"
}
}
See more examples
Grab the latest release (named-regexp-0.2.2.jar
) and include it in your classpath...
OR Maven users can simply add this dependency:
<dependency>
<groupId>com.github.tony19</groupId>
<artifactId>named-regexp</artifactId>
<version>0.2.2</version>
</dependency>
Any snapshots would be hosted in the Sonatype snapshot repository.
To build named-regexp
from source, use Maven 2 or higher:
$ git clone git://github.com/tony19/named-regexp.git
$ cd named-regexp
$ mvn package
Feel free to ask any questions at named-regexp@googlegroups.com. Please report any issues in JIRA.