de.unkrig.commons.text.pattern
Class Pattern2

java.lang.Object
  extended by de.unkrig.commons.text.pattern.Pattern2

public final class Pattern2
extends java.lang.Object

This class extends the concepts of the JDK 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.

See Also:
compile(String, int)

Field Summary
static int WILDCARD
          Modifies the pattern compilation as follows: The meaning of the '*' and '?'
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WILDCARD

public static final int WILDCARD
Modifies the pattern compilation as follows:

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)
Naturally, '*' is no longer the regex quantifier '*', so if you need to quantify 'zero or more', then you'd have to write '{0,}'. Similarly, to quantify 'zero or one', you can no longer write '?', but must use '{0,1}'.

See Also:
Constant Field Values
Method Detail

compile

public static java.util.regex.Pattern compile(java.lang.String pattern,
                                              int flags)
Like Pattern.compile(String,int), but with support for the WILDCARD flag.

See Also:
WILDCARD, Pattern.CANON_EQ, Pattern.CASE_INSENSITIVE, Pattern.COMMENTS, Pattern.DOTALL, Pattern.LITERAL, Pattern.MULTILINE, Pattern.UNICODE_CASE, Pattern.UNIX_LINES

findMeta

public 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. Metacharacters can be escaped by backslashes or by '\Q ... \E'.

Returns:
The position of the next meta character, or subject.length() iff no meta character is found