public final class Replacer extends Object
from
regex as pattern and its process(java.lang.String)
method than returns
string with all from
replaced with to
. Using the replacer should be faster
because the regex is compiled only once. Pattern.matcher(CharSequence)
and Matcher.replaceAll(String)
is used internally, hence to
parameter is regex as well and can reference matched group from the from
String.
Behavior can be further modified by Replacer.Modificator
s.Modifier and Type | Class and Description |
---|---|
static class |
Replacer.Modificator
Flags for modifying the default replacer behavior.
|
Constructor and Description |
---|
Replacer(String from,
String to,
Replacer.Modificator... modificators)
Creates the replacer with from->to regex specification.
|
Modifier and Type | Method and Description |
---|---|
String |
getTo()
Returns replacement string.
|
String |
process(String in)
Processes input, replaces all as expected and returns the result.
|
void |
setTo(String to)
Sets replacement string - this can be changed anytime with any subsequent
process(String) calls
reflecting this change immediatelly. |
String |
toString() |
public Replacer(String from, String to, Replacer.Modificator... modificators)
from
- replaced regexto
- replacement stringmodificators
- list of modificators of the behavior or pattern treatmentpublic void setTo(String to)
process(String)
calls
reflecting this change immediatelly.to
- new replacement stringpublic String process(String in)
in
- input stringCopyright © 2019. All rights reserved.