|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.jabb.util.text.RegExpSubstitution
public class RegExpSubstitution
The utility to substitute part of the String that matches specified regular
expression(s) with another specified String.
一个工具类,它可以对一个或多个正则表达式所匹配到的字符串中的内容作替换。
An instance of this class can be used many times for substitution for different Strings.
The performance overhead of each time of substitution is very small. Therefore it is very suitble
to be used in occasions that the substitution criteria is fixed while the Strings to be substituted
are of huge volume.
Please be aware that regular expressions here do not support "^" and "$"
这个类的一个实例可用来多次对不同的字符串进行替换,每次替换时的性能开销很小。因此它适合用在替换条件固定, 但待替换字符串数量巨大的情形下。 注意这里的正则表达式不支持“^”和“$”。
| Field Summary | |
|---|---|
protected static boolean |
moreSpaceForSpeed
|
protected String |
replacement
|
protected dk.brics.automaton.RunAutomaton |
runAutomation
|
| Constructor Summary | |
|---|---|
RegExpSubstitution(String replaceStr,
Collection<String> regExps)
Constructor with several regular expressions. 构造方法,用于有多个正则表达式的情况。 |
|
RegExpSubstitution(String replaceStr,
String... regExps)
Constructor with several regular expressions. 构造方法,用于有多个正则表达式的情况。 |
|
RegExpSubstitution(String replaceStr,
String regExp)
Constructor with one regular expression. 构造方法,用于只有一个正则表达式的情况。 |
|
| Method Summary | |
|---|---|
protected String |
replace(CharSequence text,
boolean firstOnly)
Do replacement. 进行替换。 |
String |
replaceAll(CharSequence text)
Replace all the occurrences. 替换所有出现的地方 |
String |
replaceFirst(CharSequence text)
Replace only the first occurrence. 只替换第一个出现的地方 |
String |
replaceLast(CharSequence text)
Replace only the last occurrence. 替换掉最后一个出现的地方 |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected dk.brics.automaton.RunAutomaton runAutomation
protected String replacement
protected static final boolean moreSpaceForSpeed
| Constructor Detail |
|---|
public RegExpSubstitution(String replaceStr,
String regExp)
replaceStr - The string to be replaced withregExp - Part of the string that matches with this regular expression will be replaced.
public RegExpSubstitution(String replaceStr,
String... regExps)
replaceStr - The string to be replaced withregExps - Part of the string that matches with any of these regular expressions will be replaced.
public RegExpSubstitution(String replaceStr,
Collection<String> regExps)
replaceStr - The string to be replaced withregExps - Part of the string that matches with any of these regular expressions will be replaced.| Method Detail |
|---|
protected String replace(CharSequence text,
boolean firstOnly)
text - The original String.firstOnly - If true, then only do replacement upon the first occurrence;
otherwise, replace in all the occurrences.public String replaceFirst(CharSequence text)
text - The original String.public String replaceAll(CharSequence text)
text - The original String.public String replaceLast(CharSequence text)
text - The original String.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||