Klasse RegexUtil

java.lang.Object
com.github.hypfvieh.util.RegexUtil

public final class RegexUtil extends Object
Utility to apply regular expressions to Strings with built-in caching.
Version:
1.2.0 - 2021-03-26
Autor:
hypfvieh
  • Methodendetails

    • splitByRegex

      public static String[] splitByRegex(String _input, String _regex)
      Splits the given input string using the given regular expression.

      Will act like String.split(String) by first checking if the split is done by a single character. If yes, then String.split(String) will be called with the given regex. If not, regex Pattern will be used (maybe from cache). If input String is null, false is returned.

      Parameter:
      _input - input string
      _regex - regular expression
      Gibt zurück:
      split string as array, maybe null
    • splitByRegex

      public static String[] splitByRegex(String _input, String _regex, int _limit)
      Splits the given input string using the given regex.

      Will act like String.split(String) by first checking if the split is done by a single character. If yes, then String.split(String) will be called with the given regex. If not, regex Pattern will be used (maybe from cache). If input String is null, false is returned.

      The _limit argument can be used as threshold to limit the returned results. If 0 or less is given, all will be returned.

      Parameter:
      _input - input string
      _regex - regular expression
      _limit - result threshold
      Gibt zurück:
      split String as array, maybe null
    • regexMatches

      public static boolean regexMatches(String _input, String _regex)
      Checks if the given regular expression matches the given string.

      If input String is null, false is returned.

      Parameter:
      _input - input string
      _regex - regular expression
      Gibt zurück:
      true if matching, false otherwise
    • extractByRegex

      public static List<String> extractByRegex(String _input, String _regex)
      Applies the regular expression to the specified string and returns all values matched by the capturing groups.
      Parameter:
      _input - input string
      _regex - regular expression, required, must contain at least one capturing groups
      Gibt zurück:
      list with content of all capturing groups, maybe empty
    • extractByRegex

      public static List<String> extractByRegex(String _input, String _regex, int _limitResults)
      Applies the regular expression to the specified string and returns all values matched by the capturing groups.

      If _limitResults is set to 0 or less, all results will be returned, otherwise only the specified amount of results is returned (or less).

      Parameter:
      _input - input string
      _regex - regular expression, required, must contain at least one capturing groups
      _limitResults - limit the result length
      Gibt zurück:
      list with content of all capturing groups, maybe empty
    • extractByRegex

      public static List<String> extractByRegex(String _input, Pattern _pattern, int _limitResults)
      Applies the regular expression to the specified string and returns all values matched by the capturing groups.

      If _limitResults is set to 0 or less, all results will be returned, otherwise only the specified amount of results is returned (or less).

      Parameter:
      _input - input string
      _pattern - regular expression pattern, required, must contain at least one capturing groups
      _limitResults - limit the result length
      Gibt zurück:
      list with content of all capturing groups, maybe empty
    • extractFirstByRegex

      public static String extractFirstByRegex(String _input, String _regex)
      Applies the regular expression to the specified string and returns the value matched by the first capturing group or null.
      Parameter:
      _input - input string
      _regex - regular expression, required, must contain at least one capturing groups
      Gibt zurück:
      value matched by first capturing group
    • extractFirstByRegex

      public static String extractFirstByRegex(String _input, Pattern _pattern)
      Applies the regular expression to the specified string and returns the value matched by the first capturing group or null.
      Parameter:
      _input - pattern
      _pattern - regular expression pattern, required, must contain at least one capturing groups
      Gibt zurück:
      value matched by first capturing group