Class RewriteRegexRule


public class RewriteRegexRule extends RegexRule

A rule to rewrite the path and query that match a regular expression pattern with a fixed string.

The replacement String follows standard Matcher.replaceAll(String) behavior, including named groups

  • Constructor Details

    • RewriteRegexRule

      public RewriteRegexRule()
    • RewriteRegexRule

      public RewriteRegexRule(@Name("regex") String regex, @Name("replacement") String replacement)
  • Method Details

    • setReplacement

      public void setReplacement(String replacement)
      Whenever a match is found, it replaces with this value.
      Parameters:
      replacement - the replacement string.
    • apply

      public Rule.Handler apply(Rule.Handler input, Matcher matcher) throws IOException
      Description copied from class: RegexRule

      Invoked after the regular expression matched the URI path to apply the rule's logic.

      Specified by:
      apply in class RegexRule
      Parameters:
      input - the input Request and Handler
      matcher - the Matcher that matched the request path, with capture groups available for replacement.
      Returns:
      the possibly wrapped Request and Handler
      Throws:
      IOException - if applying the rule failed
    • toString

      public String toString()
      Overrides:
      toString in class RegexRule