, input); where the hashmarks are used instead of slashes.
There is a special case of backslashing that you need to pay attention to. As demonstrated above, to denote a delimiter in the substituted string it must be backslashed. However, this can be a problem when you want to denote a backslash at the end of the substituted string. As of PerlTools 1.3, a new means of handling this situation has been implemented. In previous versions, the behavior was that
"... a double backslash (quadrupled in the Java String) always represents two backslashes unless the second backslash is followed by the delimiter, in which case it represents a single backslash."
The new behavior is that a backslash is always a backslash in the substitution portion of the expression unless it is used to escape a delimiter. A backslash is considered to escape a delimiter if an even number of contiguous backslashes preceed the backslash and the delimiter following the backslash is not the FINAL delimiter in the expression. Therefore, backslashes preceding final delimiters are never considered to escape the delimiter. The following, which used to be an invalid expression and require a special-case extra backslash, will now replace all instances of / with \:
numSubs = util.substitute(result, "s#/#\\#g", input);
@param result The StringBuffer in which to store the result of thesubstitutions. The buffer is only appended to.
@param expression The Perl5 substitution regular expression.
@param input The input on which to perform substitutions.
@return The number of substitutions made.
@exception MalformedPerl5PatternException If there is an error inthe expression. You are not forced to catch this exception because it is derived from RuntimeException.
@since 2.0.6