MCPcopy Create free account
hub / github.com/google/re2j / Pattern

Class Pattern

java/com/google/re2j/Pattern.java:30–362  ·  view source on GitHub ↗

A compiled representation of an RE2 regular expression, mimicking the java.util.regex.Pattern API. The matching functions take String arguments instead of the more general Java CharSequence since the latter doesn't provide UTF-16 decoding. See the <a href='package.h

Source from the content-addressed store, hash-verified

28 * @author rsc@google.com (Russ Cox)
29 */
30public final class Pattern implements Serializable {
31 /** Flag: case insensitive matching. */
32 public static final int CASE_INSENSITIVE = 1;
33
34 /** Flag: dot ({@code .}) matches all characters, including newline. */
35 public static final int DOTALL = 2;
36
37 /**
38 * Flag: multiline matching: {@code ^} and {@code $} match at beginning and end of line, not just
39 * beginning and end of input.
40 */
41 public static final int MULTILINE = 4;
42
43 /**
44 * Flag: Unicode groups (e.g. {@code \p\ Greek\} ) will be syntax errors.
45 */
46 public static final int DISABLE_UNICODE_GROUPS = 8;
47
48 /**
49 * Flag: matches longest possible string.
50 */
51 public static final int LONGEST_MATCH = 16;
52
53 // The pattern string at construction time.
54 private final String pattern;
55
56 // The flags at construction time.
57 private final int flags;
58
59 // The compiled RE2 regexp.
60 private transient final RE2 re2;
61
62 // This is visible for testing.
63 Pattern(String pattern, int flags, RE2 re2) {
64 if (pattern == null) {
65 throw new NullPointerException("pattern is null");
66 }
67 if (re2 == null) {
68 throw new NullPointerException("re2 is null");
69 }
70 this.pattern = pattern;
71 this.flags = flags;
72 this.re2 = re2;
73 }
74
75 /**
76 * Releases memory used by internal caches associated with this pattern. Does not change the
77 * observable behaviour. Useful for tests that detect memory leaks via allocation tracking.
78 */
79 public void reset() {
80 re2.reset();
81 }
82
83 /**
84 * Returns the flags used in the constructor.
85 */
86 public int flags() {
87 return flags;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…