Class RegExExtensions

java.lang.Object
io.github.astrapi69.regex.RegExExtensions

public final class RegExExtensions extends Object
Utility class for the use with regular expressions.
  • Field Details

    • VALID_CHARS_IN_FILENAME

      public static final String VALID_CHARS_IN_FILENAME
      Regular expression class for the valid characters in a filename. Current value:"[a-zA-Z0-9._-]"
      See Also:
    • VALID_EMAIL

      public static final String VALID_EMAIL
      Regular expression for the valid characters in an email. Current value:"([\w\-\.\+_]+@[\w\-\._]{2,}\.+[\w]{2,4})?"
      See Also:
    • VALID_PHONE

      public static final String VALID_PHONE
      Regular expression for the valid characters in a phone number. Current value:"^[a-zA-Z .,;:/\\-]*[ ]*[(]{0,1}[ ]*[+]{0,1}[ ]*[0-9]{0,2}[ ]*[)]{0,1}[ ]*[0-9]*[ ]*[/\\-]{0,1}[ ]*[ ]*[0-9]*[ ]*[a-zA-Z .,;:\\/-]*$"
      See Also:
    • WILDCARD_ASTERISK

      public static final String WILDCARD_ASTERISK
      Constant for the wildcard asterisk "*". Current value:"*"
      See Also:
    • WILDCARD_MANYCHARS_RE

      public static final String WILDCARD_MANYCHARS_RE
      Regular expression for many characters in the filename. Current value:".*"
      See Also:
    • WILDCARD_ONECHAR_RE

      public static final String WILDCARD_ONECHAR_RE
      Regular expression for exactly on character in the filename. Current value:"[a-zA-Z0-9._-]{1}"
      See Also:
    • WILDCARD_QUESTION_MARK

      public static final String WILDCARD_QUESTION_MARK
      Constant for the wildcard interrogation mark "?". Current value:"?"
      See Also:
  • Method Details

    • countMatches

      public static int countMatches(String regexPattern, String text)
      Count how many times the given text is matching and returns the result.
      Parameters:
      regexPattern - the regular expression pattern
      text - the text to check if it matches
      Returns:
      the count of how many times the given text is matching
    • isMatching

      public static boolean isMatching(String regexPattern, String text)
      Checks if the given regular expression pattern is matching with the given text.
      Parameters:
      regexPattern - the regular expression pattern
      text - the text to check if it matches
      Returns:
      true if the given text is matching otherwise false
    • replaceWildcardsWithRE

      public static String replaceWildcardsWithRE(String queryString)
      Replaces the normal wildcards in the given String with the corresponding regular expression wildcards.
      Parameters:
      queryString - The String to format.
      Returns:
      Returns the formatted String as a regular expression for search.
    • wildcardCriterionSQL

      public static String wildcardCriterionSQL(String query)
      Replaces the query with the wildcards asterisk "*" and interrogation mark "?" with the corresponding wildcard from SQL.
      Parameters:
      query - The String to replace the wildcards.
      Returns:
      The String with the new wildcards from SQL "%" and "_".