当前位置: 首页>>代码示例>>Java>>正文


Java Matcher.appendReplacement方法代码示例

本文整理汇总了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();
    }
 
开发者ID:rh-messaging,项目名称:Artemis-JON-plugin,代码行数:19,代码来源:ArtemisMBeanDiscoveryComponent.java

示例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;
}
 
开发者ID:guolf,项目名称:pds,代码行数:24,代码来源:HTMLFilter.java

示例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();
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:30,代码来源:ParseUtils.java

示例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"));
}
 
开发者ID:yulele166,项目名称:pub-service,代码行数:21,代码来源:JdbcDaoSupport.java

示例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();
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:30,代码来源:ParseUtils.java

示例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();
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:23,代码来源:ParseUtils.java

示例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;
}
 
开发者ID:kawasima,项目名称:bouncr,代码行数:20,代码来源:RenameColumnWorkaroundTest.java

示例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;
}
 
开发者ID:yulele166,项目名称:pub-service,代码行数:28,代码来源:StringUtil.java

示例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("&",  "&amp;")
                                      .replace("<",  "&lt;")
                                      .replace(">",  "&gt;")
                                      .replace("\"", "&quot;")
                                      .replace("'",  "&apos;"));
  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();
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:21,代码来源:XmlBackup.java

示例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());
}
 
开发者ID:davichi11,项目名称:my-spring-boot-project,代码行数:17,代码来源:HTMLFilter.java

示例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();
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:24,代码来源:DefaultResponse.java

示例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();
}
 
开发者ID:sunzhen086,项目名称:lambo,代码行数:15,代码来源:StringUtil.java

示例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();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:15,代码来源:DefaultLocalMavenRepositoryLocator.java

示例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();
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:19,代码来源:HTMLUtil.java

示例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());
}
 
开发者ID:ChalkPE,项目名称:gksduds,代码行数:13,代码来源:Gksdud.java


注:本文中的java.util.regex.Matcher.appendReplacement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。