Class Pattern

java.lang.Object
com.codename1.util.regex.Pattern

public final class Pattern extends Object

java.util.regex.Pattern for the Codename One runtime: a backtracking matcher written for this module, with the JDK's syntax and the JDK's answers for the constructs it has.

Supported
  • Literals, ., and every escape for a character: \t \n \r \f \a \e, \0nn, \xhh, \x{h...}, backslash-u with four hex digits, \cX, and \Q...\E.
  • Character classes with ranges, negation, nested unions and && intersections; \d \D \w \W \s \S \h \H \v \V; \R.
  • The POSIX classes (\p{Alpha}, \p{Punct}, ...), the java... classes, and the Unicode properties a device can answer: L, Lu, Ll, N/Nd, IsAlphabetic, IsLetter, IsDigit, IsUppercase, IsLowercase, IsWhite_Space.
  • Greedy, reluctant and possessive quantifiers.
  • Capturing, non-capturing and named groups, back references by number and by name, alternation, atomic groups.
  • Lookahead and bounded lookbehind, positive and negative.
  • ^ $ \A \z \Z \G \b \B.
  • CASE_INSENSITIVE, MULTILINE, DOTALL, COMMENTS, LITERAL, UNIX_LINES and UNICODE_CASE, as arguments and inline ((?i), (?i:...), (?-i)).
Refused

These throw PatternSyntaxException (the flags an UnsupportedOperationException) naming the construct, when the pattern is compiled. Nothing is accepted and then matched differently.

  • Unicode scripts, blocks and general categories other than the ones above (\p{IsGreek}, \p{InArrows}, \p{Sc}, ...).
  • \X, \N{name}, \b{g}.
  • CANON_EQ and UNICODE_CHARACTER_CLASS ((?U)).
  • A code point above U+FFFF inside a character class.
Differences

Text is matched one UTF-16 char at a time: . and a character class take half of a surrogate pair. Which characters are letters is what isLetter in this class answers, the scripts a device font is likely to have rather than all of Unicode. A group repeated many thousand times over a long text recurses once for each repetition, as the JDK's does, on a stack that is smaller on a device.

  • Field Details

  • Method Details

    • compile

      public static Pattern compile(String regex)
    • compile

      public static Pattern compile(String regex, int flags)
    • pattern

      public String pattern()
    • toString

      public String toString()
      Description copied from class: Object
      Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
      Overrides:
      toString in class Object
    • flags

      public int flags()
    • matcher

      public Matcher matcher(CharSequence input)
    • matches

      public static boolean matches(String regex, CharSequence input)
    • split

      public String[] split(CharSequence input)
    • split

      public String[] split(CharSequence input, int limit)
      Splits input around the matches of this pattern, by the JDK's rules for limit.
    • splitAsStream

      public Stream<String> splitAsStream(CharSequence input)
      The pieces split(CharSequence) would answer, found one at a time as the stream asks for them, as the JDK's are: the search starts on the first request, so a limit stops it and a change to a mutable input before then is seen.
    • quote

      public static String quote(String s)
      A pattern that matches s and nothing else.
    • asPredicate

      public Predicate<String> asPredicate()
    • asMatchPredicate

      public Predicate<String> asMatchPredicate()