public class Replacer extends Object
| Constructor and Description |
|---|
Replacer(Pattern pattern,
String replacement)
Convenience constructor which will not require any constant parts
(the replacement is always attempted).
|
Replacer(Pattern pattern,
String replacement,
String... necessaryConstantParts)
Replaces a pattern with a replacement, optionally provided with an array of necessary
constant parts.
|
| Modifier and Type | Method and Description |
|---|---|
String |
replace(String str)
Deprecated.
since 7.1 - use
replaceAllSkippingConstantsCheck(String) instead. |
String |
replaceAll(String str)
Checks that
str contains all of the required parts, and if
so, calls replaceAllSkippingConstantsCheck(String) to perform the
actual replacement. |
String |
replaceAllSkippingConstantsCheck(String str)
This method does exactly the same thing as
replaceAll(String), except that
it bypasses the check for the necessaryConstantParts that were provided
in the constructor. |
public Replacer(Pattern pattern, String replacement)
pattern - as for Replacer(Pattern, String, String...)}replacement - as for Replacer(Pattern, String, String...)public Replacer(Pattern pattern, String replacement, String... necessaryConstantParts)
replaceAll(String) method will not evaluate the regular
expression patterns unless the target string contains all of the necessary constant
parts. This is a performance enhancement, as substring searches are cheaper than
regular expression evaluation.pattern - the regular expression pattern to matchreplacement - the replacement expressionnecessaryConstantParts - substrings that are checked by replaceAll(String) before
evaluating the regular expressions.public String replaceAll(String str)
str contains all of the required parts, and if
so, calls replaceAllSkippingConstantsCheck(String) to perform the
actual replacement.str - the string to perform replacements uponstr if the string did not satisfy the
necessaryConstantParts or otherwise did not
need to be modified; otherwise, the modified string after
replacements have been performedIndexOutOfBoundsException - as for replaceAllSkippingConstantsCheck(String)IllegalArgumentException - as for replaceAllSkippingConstantsCheck(String)@Deprecated public String replace(String str)
replaceAllSkippingConstantsCheck(String) instead.replaceAll(String), except that
it bypasses the check for the necessaryConstantParts that were provided
in the constructor. The name of this
method is unclear and might be mistaken as a replaceFirst operation, so
it has been renamed to replaceAllSkippingConstantsCheck(String) for clarity.str - the string to perform replacement onIndexOutOfBoundsException - as for replaceAllSkippingConstantsCheck(String)IllegalArgumentException - as for replaceAllSkippingConstantsCheck(String)public String replaceAllSkippingConstantsCheck(String str)
replaceAll(String), except that
it bypasses the check for the necessaryConstantParts that were provided
in the constructor.str - the string to perform replacement onIndexOutOfBoundsException - if the replacement string ends with
an unescaped backslash (\) or dollar-sign ($),
or if a group reference is present that has no matching group,
such as $2 when the regular expression pattern only had
one capturing group.IllegalArgumentException - if the replacement string includes a
an unescaped dollar-sign ($) that is immediately
followed by a non-digit, such as ($x).Copyright © 2019 Atlassian. All rights reserved.