Class RegularExpressionUtils

java.lang.Object
fr.paris.lutece.plugins.genericattributes.util.RegularExpressionUtils

public final class RegularExpressionUtils extends Object
Matches a value typed by a user against a regular expression written by an administrator. The value comes from the front office, the expression may backtrack catastrophically: the matching is bounded in time and in length, so that a crafted answer cannot hold a server thread.
  • Method Details

    • getSyntaxError

      public static String getSyntaxError(String strRegex)
      Check that an expression compiles
      Parameters:
      strRegex - the expression
      Returns:
      the description of the syntax error, or null if the expression is valid
    • matches

      public static RegularExpressionUtils.MatchResult matches(String strRegex, String strValue)
      Match the whole value against the expression, within the time and length limits set by the properties
      Parameters:
      strRegex - the expression
      strValue - the value
      Returns:
      the result of the match
    • matches

      public static RegularExpressionUtils.MatchResult matches(String strRegex, String strValue, long nTimeoutMs, int nMaxLength)
      Match the whole value against the expression
      Parameters:
      strRegex - the expression
      strValue - the value
      nTimeoutMs - the time limit of the matching, in milliseconds
      nMaxLength - the longest value evaluated
      Returns:
      the result of the match