當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。