當前位置: 首頁>>代碼示例>>Java>>正文


Java Matcher.replaceAll方法代碼示例

本文整理匯總了Java中java.util.regex.Matcher.replaceAll方法的典型用法代碼示例。如果您正苦於以下問題:Java Matcher.replaceAll方法的具體用法?Java Matcher.replaceAll怎麽用?Java Matcher.replaceAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.regex.Matcher的用法示例。


在下文中一共展示了Matcher.replaceAll方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: delHTMLTag

import java.util.regex.Matcher; //導入方法依賴的package包/類
public static String delHTMLTag(String htmlStr) {
    if (TextUtils.isEmpty(htmlStr))
        return "";
    Pattern p_script = Pattern.compile(regEx_script,
            Pattern.CASE_INSENSITIVE);
    Matcher m_script = p_script.matcher(htmlStr);
    htmlStr = m_script.replaceAll(""); // 過濾script標簽

    Pattern p_style = Pattern
            .compile(regEx_style, Pattern.CASE_INSENSITIVE);
    Matcher m_style = p_style.matcher(htmlStr);
    htmlStr = m_style.replaceAll(""); // 過濾style標簽

    Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
    Matcher m_html = p_html.matcher(htmlStr);
    htmlStr = m_html.replaceAll(""); // 過濾html標簽

    return TextUtils.isEmpty(htmlStr) ? htmlStr : htmlStr.trim(); // 返回文本字符串
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:20,代碼來源:HTMLUtil.java

示例2: applyOnResponse

import java.util.regex.Matcher; //導入方法依賴的package包/類
@Override
public boolean applyOnResponse(Shuttle shuttle) {
	try {			
		if (!regexp.equals("")) {
			String content = shuttle.getResponseAsString();
			Matcher matcher = getRegexPattern().matcher(content);
			if (matcher.find()) {
				String resolved_replacement = shuttle.resolveVariables(replacement);
				Engine.logSiteClipper.trace("(ReplaceString) Replacing regular expression \"" + regexp + "\" with \"" + resolved_replacement +"\"");
				content = matcher.replaceAll(resolved_replacement);
				shuttle.setResponseAsString(content);
				return true;
			} else {
				Engine.logSiteClipper.trace("(ReplaceString) Replacing regular expression \"" + regexp + "\" failed because it was not found");
			}
		}
	} catch (Exception e) {
		Engine.logSiteClipper.warn("Unable to apply 'ReplaceString' rule : "+ getName(), e);
	}
	return false;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:22,代碼來源:ReplaceString.java

示例3: getExportedFilename

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * @return a statement's exported file name
 */
public static String getExportedFilename(PgStatement statement) {
    String name = statement.getBareName();
    Matcher m = FileUtils.INVALID_FILENAME.matcher(name);
    if (m.find()) {
        boolean bareNameGrouped = statement instanceof PgFunction;
        String hash = PgDiffUtils.md5(
                bareNameGrouped? statement.getBareName() : statement.getName())
                // 2^40 variants, should be enough for this purpose
                .substring(0, HASH_LENGTH);

        return m.replaceAll("") + '_' + hash; //$NON-NLS-1$
    } else {
        return name;
    }
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:19,代碼來源:ModelExporter.java

示例4: purify

import java.util.regex.Matcher; //導入方法依賴的package包/類
private String purify(String coursePage) {
    if (coursePage == null) {
        return null;
    }
    
    //Pattern pattern = Pattern.compile("<table.+?class=tableborder>(.+?</form>\r?\n\\s*</td>\r?\n\\s*</tr>)", Pattern.DOTALL);
    Pattern pattern = Pattern.compile("<td[^>]+>學年學期.+?value=\"打印\"></td>", Pattern.DOTALL);
    Matcher matcher = pattern.matcher(coursePage);
    if (matcher.find()) {
        coursePage = matcher.replaceAll("");
    }
    
    pattern = Pattern.compile("-->\r?\n\\s*<tr>.+?退出係統.+?</tr>", Pattern.DOTALL);
    matcher = pattern.matcher(coursePage);
    if (matcher.find()) {
        coursePage = matcher.replaceAll("");
    }
    
    return coursePage;
}
 
開發者ID:by-syk,項目名稱:SchTtableServer,代碼行數:21,代碼來源:NeuqGather.java

示例5: ClusterRequestWrapper

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Constructor, will check all cookies if they include
 * JSESSIONID. If they do any extra information about
 * which server this session was created for is removed.
 * 
 * @param request The request we wrap.
 */
public ClusterRequestWrapper(HttpServletRequest request) {
    super(request);
    cookies = new Vector();
    
    Enumeration reqCookies = request.getHeaders("Cookie");
    while (reqCookies.hasMoreElements()) {
        String value = (String) reqCookies.nextElement();
        Matcher matcher = sessionPattern.matcher(value);
        String replaced = matcher.replaceAll("$1");
        if (log.isDebugEnabled() && !replaced.equals(value)) {
            log.debug("Session processed, serverId removed \"" + value + "\" >> " + replaced);
        }
        cookies.add(replaced);
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:23,代碼來源:ClusterRequestWrapper.java

示例6: replaceLinks

import java.util.regex.Matcher; //導入方法依賴的package包/類
private String replaceLinks(String rawValidator) {
  String validator = rawValidator;
  for (Map.Entry<String, String> link : CSS_OBJECT_LINKS.entrySet()) {
    Matcher m = Pattern.compile(link.getKey()).matcher(validator);
    while (m.find()) {
      validator = m.replaceAll("<a target=\"_blank\" href=\"" + link.getValue() + "\">" + StringEscapeUtils.escapeHtml(m.group(0)) + "</a>");
    }
  }
  return validator;
}
 
開發者ID:racodond,項目名稱:sonar-css-plugin,代碼行數:11,代碼來源:RuleDescriptionsGenerator.java

示例7: revert

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * @see net.sf.j2ep.model.Rule#revert(java.lang.String)
 */
public String revert(String uri) {
    String rewritten = uri;
    if (isReverting) {
        Matcher matcher = revertPattern.matcher(uri);
        rewritten = matcher.replaceAll(revertTo);
        log.debug("Reverting URI: " + uri + " >> " + rewritten); 
    }
    return rewritten;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:13,代碼來源:RewriteRule.java

示例8: initialized

import java.util.regex.Matcher; //導入方法依賴的package包/類
@Override
public void initialized(IntrospectedTable introspectedTable) {
    String oldType = introspectedTable.getExampleType();
    Matcher matcher = pattern.matcher(oldType);
    oldType = matcher.replaceAll(replaceString);

    introspectedTable.setExampleType(oldType);
}
 
開發者ID:bandaotixi,項目名稱:generator_mybatis,代碼行數:9,代碼來源:RenameExampleClassPlugin.java

示例9: replaceBlank

import java.util.regex.Matcher; //導入方法依賴的package包/類
public static String replaceBlank(String str) {
    if (str != null) {
        Pattern p = Pattern.compile("\\s*|\t|\r|\n");
        Matcher m = p.matcher(str);
        String after = m.replaceAll("");
        return after;
    } else {
        return null;
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:StrUtils.java

示例10: replaceSubstitution

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Replace the matches of the from pattern in the base string with the value
 * of the to string.
 * @param base the string to transform
 * @param from the pattern to look for in the base string
 * @param to the string to replace matches of the pattern with
 * @param repeat whether the substitution should be repeated
 * @return
 */
static String replaceSubstitution(String base, Pattern from, String to, 
                                  boolean repeat) {
  Matcher match = from.matcher(base);
  if (repeat) {
    return match.replaceAll(to);
  } else {
    return match.replaceFirst(to);
  }
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:19,代碼來源:KerberosName.java

示例11: validatePropertyValue

import java.util.regex.Matcher; //導入方法依賴的package包/類
private static String validatePropertyValue(String value) {
    final Matcher m = INVALID_NAME.matcher(value);
    if (m.find()) {
        value = m.replaceAll("_");  //NOI18N
    }
    return value;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:8,代碼來源:JFXProjectGenerator.java

示例12: replaceSubstitution

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Replace the matches of the from pattern in the base string with the value
 * of the to string.
 * @param base the string to transform
 * @param from the pattern to look for in the base string
 * @param to the string to replace matches of the pattern with
 * @param repeat whether the substitution should be repeated
 * @return
 */
static String replaceSubstitution(String base, Pattern from, String to,
                                  boolean repeat) {
  Matcher match = from.matcher(base);
  if (repeat) {
    return match.replaceAll(to);
  } else {
    return match.replaceFirst(to);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:KerberosName.java

示例13: transformAllLineSeparators

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Replaces all possible line feed character combinations by &quot;\n&quot;. This might be
 * important for GUI purposes like tool tip texts which do not support carriage return
 * combinations.
 */
public static String transformAllLineSeparators(String text) {
	Pattern crlf = Pattern.compile("(\r\n|\r|\n|\n\r)");
	Matcher m = crlf.matcher(text);
	if (m.find()) {
		text = m.replaceAll("\n");
	}
	return text;
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:14,代碼來源:Tools.java

示例14: processLine

import java.util.regex.Matcher; //導入方法依賴的package包/類
private static String processLine(String line) {
  Matcher m = TO_REMOVE_FROM_LOG_LINES_RE.matcher(line);
  return m.replaceAll("");
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:5,代碼來源:ProcessBasedLocalHBaseCluster.java

示例15: eventCheck

import java.util.regex.Matcher; //導入方法依賴的package包/類
private String eventCheck(String text)
{
    Pattern pattern = Pattern.compile(EVENT_PATTERN, Pattern.MULTILINE);
    Matcher matcher = pattern.matcher(text);

    DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT);

    // Find matches
    while (matcher.find())
    {
        // Parse time
        Date date = null;
        try
        {
            date = dateFormat.parse(matcher.group(1));
        }

        // Ignore errors
        catch (Exception e)
        {
            continue;
        }

        Calendar time = Calendar.getInstance();
        time.setTime(date);

        Calendar startTime =
            new GregorianCalendar(currEntry.get(Calendar.YEAR),
                                  currEntry.get(Calendar.MONTH),
                                  currEntry.get(Calendar.DATE),
                                  time.get(Calendar.HOUR_OF_DAY),
                                  time.get(Calendar.MINUTE));
        Calendar endTime =
            new GregorianCalendar(currEntry.get(Calendar.YEAR),
                                  currEntry.get(Calendar.MONTH),
                                  currEntry.get(Calendar.DATE),
                                  time.get(Calendar.HOUR_OF_DAY),
                                  time.get(Calendar.MINUTE));
        // Add an hour
        endTime.add(Calendar.HOUR, 1);

        String title = matcher.group(2);

        QueryHandler.insertEvent(this, startTime.getTimeInMillis(),
                                 endTime.getTimeInMillis(), title);
    }

    return matcher.replaceAll(EVENT_TEMPLATE);
}
 
開發者ID:billthefarmer,項目名稱:diary,代碼行數:50,代碼來源:Diary.java


注:本文中的java.util.regex.Matcher.replaceAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。