本文整理汇总了Java中java.util.regex.Matcher.appendReplacement方法的典型用法代码示例。如果您正苦于以下问题:Java Matcher.appendReplacement方法的具体用法?Java Matcher.appendReplacement怎么用?Java Matcher.appendReplacement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.regex.Matcher
的用法示例。
在下文中一共展示了Matcher.appendReplacement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: substituteConfigProperties
import java.util.regex.Matcher; //导入方法依赖的package包/类
private String substituteConfigProperties(String objectName, Configuration configuration, boolean isParent) {
final Pattern p;
if (isParent) {
p = PROPERTY_NAME_PATTERN;
} else {
p = OBJECT_NAME_PROPERTY_PATTERN;
}
StringBuffer buffer = new StringBuffer();
final Matcher m = p.matcher(objectName);
while (m.find()) {
String name = m.group(1);
m.appendReplacement(buffer, configuration.getSimpleValue(name));
}
m.appendTail(buffer);
return buffer.toString();
}
示例2: checkTags
import java.util.regex.Matcher; //导入方法依赖的package包/类
private String checkTags(String s) {
Matcher m = P_TAGS.matcher(s);
final StringBuffer buf = new StringBuffer();
while (m.find()) {
String replaceStr = m.group(1);
replaceStr = processTag(replaceStr);
m.appendReplacement(buf, Matcher.quoteReplacement(replaceStr));
}
m.appendTail(buf);
s = buf.toString();
// these get tallied in processTag
// (remember to reset before subsequent calls to filter method)
for (String key : vTagCounts.keySet()) {
for (int ii = 0; ii < vTagCounts.get(key); ii++) {
s += "</" + key + ">";
}
}
return s;
}
示例3: interpolate
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* 执行interpolation(变量插入)。
*
* @param expression 含有变量的表达式字符串。表达式中的变量名也可以用<code>{}</code>括起来。
* @param params 变量集。变量名可以包含<code>.</code>、<code>_</code>字符。
* @return 完成interpolation后的字符串。 如:<code><pre>xxx${name}zzz -> xxxjerryzzz</pre></code>(其中变量name="jerry")
* @throws IllegalStateException 表达式字符串中使用到的变量 在变量集中没有
*/
// FIMXE 抛出IllegalStateException异常,是否合适?!
public static String interpolate(String expression, Map<String, String> params) {
if (expression == null || expression.length() == 0) {
throw new IllegalArgumentException("glob pattern is empty!");
}
if (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 = params == null ? null : params.get(key);
if (value == null) {
value = "";
}
matcher.appendReplacement(sb, value);
}
matcher.appendTail(sb);
return sb.toString();
}
示例4: removeSelect
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* 去除sql的select 子句,未考虑union的情况,用于pagedQuery.
*
* @see #pagedQuery(String,int,int,Object[])
*/
private String removeSelect(String sql){
sql=sql.toLowerCase();
Pattern p = Pattern.compile("\\(.*\\)",Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(sql);
StringBuffer sb = new StringBuffer();
while (m.find()) {
int c = m.end()-m.start();
m.appendReplacement(sb, getStr(c,"~"));
}
m.appendTail(sb);
String replacedSql = sb.toString();
return sql.substring(replacedSql.indexOf("from"));
}
示例5: interpolate
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* 执行interpolation(变量插入)。
*
* @param expression 含有变量的表达式字符串。表达式中的变量名也可以用<code>{}</code>括起来。
* @param params 变量集。变量名可以包含<code>.</code>、<code>_</code>字符。
* @return 完成interpolation后的字符串。 如:<code><pre>xxx${name}zzz -> xxxjerryzzz</pre></code>(其中变量name="jerry")
* @throws IllegalStateException 表达式字符串中使用到的变量 在变量集中没有
*/
// FIMXE 抛出IllegalStateException异常,是否合适?!
public static String interpolate(String expression, Map<String, String> params) {
if (expression == null || expression.length() == 0) {
throw new IllegalArgumentException("glob pattern is empty!");
}
if (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 = params == null ? null: params.get(key);
if (value == null) {
value = "";
}
matcher.appendReplacement(sb, value);
}
matcher.appendTail(sb);
return sb.toString();
}
示例6: replaceParameter
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* 替换url中参数的值。
*/
public static String replaceParameter(String query, String key, String value) {
if (query == null || query.length() == 0) {
return key + "=" + value;
}
if (query.indexOf(key + "=") == -1) {
return query + "&" + key + "=" + value;
}
Pattern pattern = REPLACE_PARAMETER_PATTERNS.get(key);
if (pattern == null) {
pattern = Pattern.compile(key.replaceAll("([^(_0-9A-Za-z)])", "\\\\$0") + "=[^&]+");
}
Matcher matcher = pattern.matcher(query);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, (key + "=" + value).replace("$", "\\$"));
}
matcher.appendTail(sb);
return sb.toString();
}
示例7: createDDL
import java.util.regex.Matcher; //导入方法依赖的package包/类
private String createDDL(DefaultConfiguration config) {
DSLContext create = DSL.using(config);
String ddl = create.alterTable(table("oidc_invitations"))
.renameColumn(field("oidc_sub"))
.to(field("oidc_payload", SQLDataType.CLOB))
.getSQL();
if (create.configuration().dialect() == SQLDialect.MYSQL) {
Matcher m = Pattern.compile("\\s+RENAME\\s+COLUMN\\s+(\\w+)\\s+TO\\s+", Pattern.CASE_INSENSITIVE).matcher(ddl);
StringBuffer sb = new StringBuffer();
if (m.find()) {
m.appendReplacement(sb, " change " + m.group(1) + " ");
m.appendTail(sb);
sb.append(" text not null");
ddl = sb.toString();
}
}
return ddl;
}
示例8: getTxtWithoutHTMLElement
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* 去除HTML 元素
*
* @param element
* @return
*/
public static String getTxtWithoutHTMLElement(String element) {
if (null == element || "".equals(element.trim())) {
return element;
}
Pattern pattern = Pattern.compile("<[^<|^>]*>");
Matcher matcher = pattern.matcher(element);
StringBuffer txt = new StringBuffer();
while (matcher.find()) {
String group = matcher.group();
if (group.matches("<[\\s]*>")) {
matcher.appendReplacement(txt, group);
} else {
matcher.appendReplacement(txt, "");
}
}
matcher.appendTail(txt);
String temp = txt.toString().replaceAll("\n", "");
temp = temp.replaceAll(" ", "");
return temp;
}
示例9: escapeXML
import java.util.regex.Matcher; //导入方法依赖的package包/类
private String escapeXML(String s) {
if (TextUtils.isEmpty(s)) return s;
Matcher matcher = PATTERN.matcher( s.replace("&", "&")
.replace("<", "<")
.replace(">", ">")
.replace("\"", """)
.replace("'", "'"));
StringBuffer st = new StringBuffer();
while (matcher.find()) {
String escaped="";
for (char ch: matcher.group(0).toCharArray()) {
escaped += ("&#" + ((int) ch) + ";");
}
matcher.appendReplacement(st, escaped);
}
matcher.appendTail(st);
return st.toString();
}
示例10: validateEntities
import java.util.regex.Matcher; //导入方法依赖的package包/类
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());
}
示例11: sanitizeUrl
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* Sanitize a URL provided by a relying party by normalizing non-printable
* ASCII character sequences into spaces. This functionality protects
* against CRLF attacks and other similar attacks using invisible characters
* that could be abused to trick user agents.
*
* @param url URL to sanitize.
* @return Sanitized URL string.
*/
private static String sanitizeUrl(final String url) {
final Matcher m = NON_PRINTABLE.matcher(url);
final StringBuffer sb = new StringBuffer(url.length());
boolean hasNonPrintable = false;
while (m.find()) {
m.appendReplacement(sb, " ");
hasNonPrintable = true;
}
m.appendTail(sb);
if (hasNonPrintable) {
LOGGER.warn("The following redirect URL has been sanitized and may be sign of attack:\n[{}]", url);
}
return sb.toString();
}
示例12: humpToLine
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* 驼峰转下划线,效率比上面高
* @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();
}
示例13: resolvePlaceholders
import java.util.regex.Matcher; //导入方法依赖的package包/类
private String resolvePlaceholders(String value) {
StringBuffer result = new StringBuffer();
Matcher matcher = PLACEHOLDER_PATTERN.matcher(value);
while (matcher.find()) {
String placeholder = matcher.group(1);
String replacement = placeholder.startsWith("env.") ? system.getEnv(placeholder.substring(4)) : system.getProperty(placeholder);
if (replacement == null) {
throw new CannotLocateLocalMavenRepositoryException(String.format("Cannot resolve placeholder '%s' in value '%s'", placeholder, value));
}
matcher.appendReplacement(result, Matcher.quoteReplacement(replacement));
}
matcher.appendTail(result);
return result.toString();
}
示例14: filterHtml
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* 基本功能:过滤所有以"<"开头以">"结尾的标签
*
* @param str
* @return String
*/
public static String filterHtml(String str) {
Pattern pattern = Pattern.compile(regxpForHtml);
Matcher matcher = pattern.matcher(str);
StringBuffer sb = new StringBuffer();
boolean result1 = matcher.find();
while (result1) {
matcher.appendReplacement(sb, "");
result1 = matcher.find();
}
matcher.appendTail(sb);
return sb.toString();
}
示例15: gksdud
import java.util.regex.Matcher; //导入方法依赖的package包/类
private static String gksdud(String str){
final StringBuffer buffer = new StringBuffer();
final Matcher matcher = HANGEUL_SYLLABLE.matcher(reverse(replaceAlphabets(str)));
while(matcher.find()){
final String finalJamo = reverse(matcher.group(1)), medialJamo = reverse(matcher.group(2)), initialJamo = reverse(matcher.group(3));
matcher.appendReplacement(buffer, stackHangeulJamos(initialJamo, COMPLEX_MEDIAL_JAMOS.getOrDefault(medialJamo, medialJamo), COMPLEX_FINAL_JAMOS.getOrDefault(finalJamo, finalJamo)));
}
matcher.appendTail(buffer);
return reverse(buffer.toString());
}