public class RegexUtil extends @NonNull Object
For an example of intended use, see section Testing whether a string is a regular expression in the Checker Framework manual.
Runtime Dependency: Using this class introduces a runtime dependency. This means that you need to distribute (or link to) the Checker Framework, along with your binaries. To eliminate this dependency, you can simply copy this class into your own project.
Modifier and Type | Method and Description |
---|---|
static @ReadOnly String |
asRegex(@ReadOnly String s)
Returns the argument as a
@Regex String if it is a regex,
otherwise throws an error. |
static @ReadOnly String |
asRegex(@ReadOnly String s,
int groups)
Returns the argument as a
@Regex(groups) String if it is a regex
with at least the given number of groups, otherwise throws an error. |
static boolean |
isRegex(char c)
Returns true if the argument is a syntactically valid regular
expression.
|
static boolean |
isRegex(@ReadOnly String s)
Returns true if the argument is a syntactically valid regular
expression.
|
static boolean |
isRegex(@ReadOnly String s,
int groups)
Returns true if the argument is a syntactically valid regular
expression with at least the given number of groups.
|
static @ReadOnly String |
regexError(@ReadOnly String s)
Returns null if the argument is a syntactically valid regular
expression.
|
static @ReadOnly String |
regexError(@ReadOnly String s,
int groups)
Returns null if the argument is a syntactically valid regular
expression with at least the given number of groups.
|
static @Nullable PatternSyntaxException |
regexException(@ReadOnly String s)
Returns null if the argument is a syntactically valid regular
expression.
|
static @Nullable PatternSyntaxException |
regexException(@ReadOnly String s,
int groups)
Returns null if the argument is a syntactically valid regular
expression with at least the given number of groups.
|
public static boolean isRegex(@ReadOnly String s)
public static boolean isRegex(@ReadOnly String s, int groups)
public static boolean isRegex(char c)
public static @ReadOnly String regexError(@ReadOnly String s)
public static @ReadOnly String regexError(@ReadOnly String s, int groups)
public static @Nullable PatternSyntaxException regexException(@ReadOnly String s)
public static @Nullable PatternSyntaxException regexException(@ReadOnly String s, int groups)
public static @ReadOnly String asRegex(@ReadOnly String s)
@Regex String
if it is a regex,
otherwise throws an error. The purpose of this method is to suppress Regex
Checker warnings. Once the the Regex Checker supports flow-sensitivity, it
should be very rarely needed.public static @ReadOnly String asRegex(@ReadOnly String s, int groups)
@Regex(groups) String
if it is a regex
with at least the given number of groups, otherwise throws an error. The
purpose of this method is to suppress Regex Checker warnings. Once the the
Regex Checker supports flow-sensitivity, it should be very rarely needed.