Class StringUtils.Rewriter

  • Enclosing class:
    StringUtils

    public abstract static class StringUtils.Rewriter
    extends Object
    A matcher-based string rewriter.
    • Constructor Detail

      • Rewriter

        public Rewriter​(String regex)
        Constructs a rewriter using the given regular expression; the syntax is the same as for 'Pattern.compile'.
        Parameters:
        regex - Regular expression to find substrings to replace
    • Method Detail

      • group

        public String group​(int i)
        Returns the input subsequence captured by the given group during the previous match operation.
        Parameters:
        i - Group number
        Returns:
        Subsequence by number
      • replacement

        public abstract String replacement()
        Overridden to compute a replacement for each match. Use the method 'group' to access the captured groups.
        Returns:
        The string that will replace the current group found by the matcher
      • rewrite

        public String rewrite​(CharSequence original)
        Returns the result of rewriting 'original' by invoking the method 'replacement' for each match of the regular expression supplied to the constructor.
        Parameters:
        original - The character sequence to be rewritten
        Returns:
        Rewritten sequence as a string