本文整理匯總了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());
}