当前位置: 首页>>代码示例>>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;未经允许,请勿转载。