Package com.google.re2j
This package provides an implementation of regular expression matching based on Russ Cox's linear-time RE2 algorithm.
The API presented by com.google.re2j mimics that of
java.util.regex.Matcher and java.util.regex.Pattern.
While not identical, they are similar enough that most users can
switch implementations simply by changing their imports.
The syntax of the regular expressions accepted is the same general
syntax used by Perl, Python, and other languages. More precisely,
it is the syntax accepted by the C++ and Go implementations of RE2
described at https://github.com/google/re2/wiki/Syntax,
except for \C (match any byte), which is not
supported because in this implementation, the matcher's input is
conceptually a stream of Unicode code points, not bytes.
The current API is rather small and intended for compatibility
with java.util.regex, but the underlying implementation
supports some additional features, such as the ability to process
input character streams encoded as UTF-8 byte arrays. These may
be exposed in a future release if there is sufficient interest.
Example use:
import com.google.re2j.Matcher;
import com.google.re2j.Pattern;
Pattern p = Pattern.compile("b(an)*(.)");
Matcher m = p.matcher("by, band, banana");
assertTrue(m.lookingAt());
m.reset(); // "by, band, banana"
assertTrue(m.find());
assertEquals("by", m.group(0)); // --
assertEquals(null, m.group(1)); //
assertEquals("y", m.group(2)); // ^
assertTrue(m.find());
assertEquals("band", m.group(0)); // ----
assertEquals("an", m.group(1)); // ^^
assertEquals("d", m.group(2)); // ^
assertTrue(m.find());
assertEquals("banana", m.group(0)); // -------
assertEquals("an", m.group(1)); // ^^
assertEquals("a", m.group(2)); // ^
assertFalse(m.find());
-
Interface Summary Interface Description RE2.DeliverFunc RE2.ReplaceFunc -
Class Summary Class Description Characters Wraps Character methods to be overridden for GWT.CharClass A "builder"-style helper class for manipulating character classes represented as an array of pairs of runes [lo, hi], each denoting an inclusive interval.CharGroup Compiler Compiler fromRegexp(RE2 abstract syntax) toRE2(compiled regular expression).Compiler.Frag A fragment of a compiled regular expression program.Inst A single instruction in the regular expression virtual machine.Machine Machine.Queue Machine.Thread MachineInput MachineInput abstracts different representations of the input text supplied to the Machine.MachineInput.UTF16Input MachineInput.UTF8Input Matcher A stateful iterator that interprets a regexPatternon a specific input.MatcherInput Abstract the representations of input text supplied to Matcher.MatcherInput.Utf16MatcherInput MatcherInput.Utf8MatcherInput Parser A parser of regular expression patterns.Parser.Pair<F,S> Parser.Stack Parser.StringIterator Pattern A compiled representation of an RE2 regular expression, mimicking thejava.util.regex.PatternAPI.Prog A Prog is a compiled regular expression program.RE2 An RE2 class instance is a compiled representation of an RE2 regular expression, independent of the public Java-like Pattern/Matcher API.Regexp Regular expression abstract syntax tree.Simplify Unicode Utilities for dealing with Unicode better than Java does.UnicodeTables Utils Various constants and helper utilities. -
Enum Summary Enum Description MatcherInput.Encoding Regexp.Op -
Exception Summary Exception Description PatternSyntaxException An exception thrown by the parser if the pattern was invalid.