public final class Pattern2
extends java.lang.Object
java.util.regex.Pattern class with a new WILDCARD compilation flag, which modifies the pattern compilation such that it combines the well-known
wildcard pattern matching with the power of regular
expressions.compile(String, int)| Modifier and Type | Field and Description |
|---|---|
static int |
WILDCARD
Modifies the pattern compilation as follows:
The meaning of the '*' and '?'
|
| Modifier and Type | Method and Description |
|---|---|
static java.util.regex.Pattern |
compile(java.lang.String pattern,
int flags)
Like
Pattern.compile(String,int), but with support for the WILDCARD flag. |
static int |
findMeta(java.lang.String metaCharacters,
java.lang.String subject,
int offset)
Finds the next unescaped occurrence of one of the
metaCharacters within subject, starting at
position offset. |
public static final int WILDCARD
The meaning of the '*' and '?' metacharacters is now different, and '.' is no longer a metacharacter.
'/' is now a metacharacter, i.e. to include it literally in the pattern, it must be escaped with a backslash.
The semantics of '*', '?' and '.' are as follows:
| Construct | Matches |
|---|---|
| Wildcards | |
| * | Zero or more characters except '/', the file separator and '!' |
| ** | Zero or more characters except '!' |
| *** | Zero or more characters |
| ? | Any character except '/', the file separator and '!' |
| . | The '.' |
| / |
'/' or the system-dependent file separator (see separatorChar)
|
{0,}'. Similarly, to quantify 'zero or one', you can no longer write '?', but
must use '{0,1}'.public static java.util.regex.Pattern compile(java.lang.String pattern,
int flags)
Pattern.compile(String,int), but with support for the WILDCARD flag.
Notice that iff WILDCARD is given, then Object.toString() returns the regular expression
that was generated from the wildcard pattern (and not the wildcard pattern, as you'd probably expect).
WILDCARD,
Pattern.CANON_EQ,
Pattern.CASE_INSENSITIVE,
Pattern.COMMENTS,
Pattern.DOTALL,
Pattern.LITERAL,
Pattern.MULTILINE,
Pattern.UNICODE_CASE,
Pattern.UNIX_LINESpublic static int findMeta(java.lang.String metaCharacters,
java.lang.String subject,
int offset)
metaCharacters within subject, starting at
position offset. Metacharacters can be escaped by backslashes or by '\Q ... \E'.subject.length() iff no meta character is found