Class PerlSubstitution

  • All Implemented Interfaces:
    Substitution

    public class PerlSubstitution
    extends java.lang.Object
    implements Substitution
    An implementation of the Substitution interface. Performs substitutions in accordance with Perl-like substitution scripts.
    The latter is a string, containing a mix of memory register references and plain text blocks.
    It may look like "some_chars $1 some_chars$2some_chars" or "123${1}45${2}67".
    A tag consisting of '$',not preceeded by the escape character'\' and followed by some digits (possibly enclosed in the curled brackets) is interpreted as a memory register reference, the digits forming a register ID. All the rest is considered as a plain text.
    Upon the Replacer has found a text block that matches the pattern, a references in a replacement string are replaced by the contents of corresponding memory registers, and the resulting text replaces the matched block.
    For example, the following code:
     System.out.println("\""+
        new Replacer(new Pattern("\\b(\\d+)\\b"),new PerlSubstitution("'$1'")).replace("abc 123 def")
        +"\"");
     
    will print "abc '123' def".
    See Also:
    Substitution, Replacer, Pattern
    • Constructor Detail

      • PerlSubstitution

        public PerlSubstitution​(java.lang.String s)