本文整理了Java中java.util.regex.Matcher.appendTail()
方法的一些代码示例,展示了Matcher.appendTail()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matcher.appendTail()
方法的具体详情如下:
包路径:java.util.regex.Matcher
类名称:Matcher
方法名:appendTail
[英]Appends the (unmatched) remainder of the input to the given StringBuffer. The method can be used in conjunction with #find() and #appendReplacement(StringBuffer,String) to walk through the input and replace all matches of the Patternwith something else.
[中]将输入的剩余部分(不匹配)追加到给定的StringBuffer。该方法可以与#find()和#appendReplacement(StringBuffer,String)结合使用,遍历输入并用其他内容替换模式的所有匹配项。
代码示例来源:origin: shuzheng/zheng
/**
* 驼峰转下划线,效率比上面高
* @param str
* @return
*/
public static String humpToLine(String str) {
Matcher matcher = humpPattern.matcher(str);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
}
matcher.appendTail(sb);
return sb.toString();
}
代码示例来源:origin: apache/incubator-dubbo
public static String replaceProperty(String expression, Map<String, String> params) {
if (expression == null || expression.length() == 0 || expression.indexOf('$') < 0) {
return expression;
}
Matcher matcher = VARIABLE_PATTERN.matcher(expression);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
String key = matcher.group(1);
String value = System.getProperty(key);
if (value == null && params != null) {
value = params.get(key);
}
if (value == null) {
value = "";
}
matcher.appendReplacement(sb, Matcher.quoteReplacement(value));
}
matcher.appendTail(sb);
return sb.toString();
}
代码示例来源:origin: apache/incubator-dubbo
public static String replaceProperty(String expression, Map<String, String> params) {
if (expression == null || expression.length() == 0 || expression.indexOf('$') < 0) {
return expression;
}
Matcher matcher = VARIABLE_PATTERN.matcher(expression);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
String key = matcher.group(1);
String value = System.getProperty(key);
if (value == null && params != null) {
value = params.get(key);
}
if (value == null) {
value = "";
}
matcher.appendReplacement(sb, Matcher.quoteReplacement(value));
}
matcher.appendTail(sb);
return sb.toString();
}
代码示例来源:origin: hs-web/hsweb-framework
public static String parse ( String input ) {
Pattern pattern = Pattern.compile("\\{([^\\}]+)\\}", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(input);
PathFormat.currentDate = new Date();
StringBuffer sb = new StringBuffer();
while ( matcher.find() ) {
matcher.appendReplacement(sb, PathFormat.getString(matcher.group(1)) );
}
matcher.appendTail(sb);
return sb.toString();
}
代码示例来源:origin: shuzheng/zheng
/**
* 下划线转驼峰
* @param str
* @return
*/
public static String lineToHump(String str) {
if (null == str || "".equals(str)) {
return str;
}
str = str.toLowerCase();
Matcher matcher = linePattern.matcher(str);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
}
matcher.appendTail(sb);
str = sb.toString();
str = str.substring(0, 1).toUpperCase() + str.substring(1);
return str;
}
代码示例来源:origin: stackoverflow.com
StringBuffer resultString = new StringBuffer();
Pattern regex = Pattern.compile("regex");
Matcher regexMatcher = regex.matcher(subjectString);
while (regexMatcher.find()) {
// You can vary the replacement text for each match on-the-fly
regexMatcher.appendReplacement(resultString, "replacement");
}
regexMatcher.appendTail(resultString);
代码示例来源:origin: lets-blade/blade
private String escapeComments(final String s) {
final Matcher m = P_COMMENTS.matcher(s);
final StringBuffer buf = new StringBuffer();
if (m.find()) {
final String match = m.group(1); //(.*?)
m.appendReplacement(buf, Matcher.quoteReplacement("<!--" + htmlSpecialChars(match) + "-->"));
}
m.appendTail(buf);
return buf.toString();
}
代码示例来源:origin: google/ExoPlayer
private static String replaceVariableReferences(
String string, Map<String, String> variableDefinitions) {
Matcher matcher = REGEX_VARIABLE_REFERENCE.matcher(string);
// TODO: Replace StringBuffer with StringBuilder once Java 9 is available.
StringBuffer stringWithReplacements = new StringBuffer();
while (matcher.find()) {
String groupName = matcher.group(1);
if (variableDefinitions.containsKey(groupName)) {
matcher.appendReplacement(
stringWithReplacements, Matcher.quoteReplacement(variableDefinitions.get(groupName)));
} else {
// The variable is not defined. The value is ignored.
}
}
matcher.appendTail(stringWithReplacements);
return stringWithReplacements.toString();
}
代码示例来源:origin: lets-blade/blade
private String escapeComments(final String s) {
final Matcher m = P_COMMENTS.matcher(s);
final StringBuffer buf = new StringBuffer();
if (m.find()) {
final String match = m.group(1); //(.*?)
m.appendReplacement(buf, Matcher.quoteReplacement("<!--" + htmlSpecialChars(match) + "-->"));
}
m.appendTail(buf);
return buf.toString();
}
代码示例来源:origin: plantuml/plantuml
public static String manageAmpDiese(String s) {
final Pattern pattern = Pattern.compile("\\&#([0-9]+);");
final Matcher matcher = pattern.matcher(s);
final StringBuffer result = new StringBuffer();
while (matcher.find()) {
final String num = matcher.group(1);
final char c = (char) Integer.parseInt(num);
matcher.appendReplacement(result, "" + c);
}
matcher.appendTail(result);
return result.toString();
}
代码示例来源:origin: nutzam/nutz
public static String unicodeDecode(String s) {
Matcher m = reUnicode.matcher(s);
StringBuffer sb = new StringBuffer(s.length());
while (m.find()) {
m.appendReplacement(sb, Character.toString((char) Integer.parseInt(m.group(1), 16)));
}
m.appendTail(sb);
return sb.toString();
}
代码示例来源:origin: plantuml/plantuml
public static String manageUnicodeNotationUplus(String s) {
final Pattern pattern = Pattern.compile("\\<U\\+([0-9a-fA-F]{4,5})\\>");
final Matcher matcher = pattern.matcher(s);
final StringBuffer result = new StringBuffer();
while (matcher.find()) {
final String num = matcher.group(1);
final int value = Integer.parseInt(num, 16);
matcher.appendReplacement(result, new String(Character.toChars(value)));
}
matcher.appendTail(result);
return result.toString();
}
代码示例来源:origin: stackoverflow.com
Map<String,String> tokens = new HashMap<String,String>();
tokens.put("cat", "Garfield");
tokens.put("beverage", "coffee");
String template = "%cat% really needs some %beverage%.";
// Create pattern of the format "%(cat|beverage)%"
String patternString = "%(" + StringUtils.join(tokens.keySet(), "|") + ")%";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(template);
StringBuffer sb = new StringBuffer();
while(matcher.find()) {
matcher.appendReplacement(sb, tokens.get(matcher.group(1)));
}
matcher.appendTail(sb);
System.out.println(sb.toString());
代码示例来源:origin: GitLqr/LQRWeChat
private String getEmotion(String var1) {
Pattern var2 = Pattern.compile("\\[/u([0-9A-Fa-f]+)\\]");
Matcher var3 = var2.matcher(var1);
StringBuffer var4 = new StringBuffer();
while (var3.find()) {
int var5 = Integer.parseInt(var3.group(1), 16);
var3.appendReplacement(var4, String.valueOf(Character.toChars(var5)));
}
var3.appendTail(var4);
return var4.toString();
}
代码示例来源:origin: GitLqr/LQRWeChat
private String getEmotion(String var1) {
Pattern var2 = Pattern.compile("\\[/u([0-9A-Fa-f]+)\\]");
Matcher var3 = var2.matcher(var1);
StringBuffer var4 = new StringBuffer();
while (var3.find()) {
int var5 = Integer.parseInt(var3.group(1), 16);
var3.appendReplacement(var4, String.valueOf(Character.toChars(var5)));
}
var3.appendTail(var4);
return var4.toString();
}
代码示例来源:origin: looly/hutool
private String escapeComments(final String s) {
final Matcher m = P_COMMENTS.matcher(s);
final StringBuffer buf = new StringBuffer();
if (m.find()) {
final String match = m.group(1); // (.*?)
m.appendReplacement(buf, Matcher.quoteReplacement("<!--" + htmlSpecialChars(match) + "-->"));
}
m.appendTail(buf);
return buf.toString();
}
代码示例来源:origin: looly/hutool
private String escapeComments(final String s) {
final Matcher m = P_COMMENTS.matcher(s);
final StringBuffer buf = new StringBuffer();
if (m.find()) {
final String match = m.group(1); // (.*?)
m.appendReplacement(buf, Matcher.quoteReplacement("<!--" + htmlSpecialChars(match) + "-->"));
}
m.appendTail(buf);
return buf.toString();
}
代码示例来源:origin: lets-blade/blade
private String validateEntities(final String s) {
StringBuffer buf = new StringBuffer();
// validate entities throughout the string
Matcher m = P_VALID_ENTITIES.matcher(s);
while (m.find()) {
final String one = m.group(1); //([^&;]*)
final String two = m.group(2); //(?=(;|&|$))
m.appendReplacement(buf, Matcher.quoteReplacement(checkEntity(one, two)));
}
m.appendTail(buf);
return encodeQuotes(buf.toString());
}
代码示例来源:origin: lets-blade/blade
private String validateEntities(final String s) {
StringBuffer buf = new StringBuffer();
// validate entities throughout the string
Matcher m = P_VALID_ENTITIES.matcher(s);
while (m.find()) {
final String one = m.group(1); //([^&;]*)
final String two = m.group(2); //(?=(;|&|$))
m.appendReplacement(buf, Matcher.quoteReplacement(checkEntity(one, two)));
}
m.appendTail(buf);
return encodeQuotes(buf.toString());
}
代码示例来源:origin: stackoverflow.com
Pattern p = Pattern.compile("cat");
Matcher m = p.matcher("one cat two cats in the yard");
StringBuffer sb = new StringBuffer();
while (m.find()) {
m.appendReplacement(sb, "dog");
}
m.appendTail(sb);
System.out.println(sb.toString());
内容来源于网络,如有侵权,请联系作者删除!