本文整理汇总了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(); // 返回文本字符串
}
示例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;
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例13: transformAllLineSeparators
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* Replaces all possible line feed character combinations by "\n". 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;
}
示例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("");
}
示例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);
}