List of usage examples for java.util.regex Matcher replaceAll
public String replaceAll(Function<MatchResult, String> replacer)
From source file:com.gewara.util.XSSFilter.java
/** * // w ww .j ava 2s . c o m */ public static String filterSpecStr(String str) { // str = BCConvert.SBC2DBC(str); Pattern p = Pattern.compile(regExp); Matcher m = p.matcher(str); return m.replaceAll("").trim(); }
From source file:org.eclipse.buckminster.jnlp.p2.MaterializationUtils.java
/** * Generalize <code>IPath</code> * // w ww . ja va2 s . c o m * @param mspec * @param installLocation * @return */ public static IPath generalizePath(MaterializationSpecBuilder mspec, IPath installLocation) { if (installLocation == null) return null; Set<PropertyEntryByLength> properties = m_generalizeProperties.get(mspec); if (properties == null) { properties = new TreeSet<PropertyEntryByLength>(); RMContext context = new RMContext(mspec.getProperties()); for (String key : context.keySet()) { String value = (String) context.get(key); if (value == null || value.length() == 0) continue; // unifying file separators String unifiedValue = new Path(value).removeTrailingSeparator().toString(); // changing meaning - key is value, value is key properties.add(new PropertyEntryByLength(unifiedValue, key)); } m_generalizeProperties.put(mspec, properties); } String pathToGeneralize = installLocation.addTrailingSeparator().toString(); int len = pathToGeneralize.length(); for (PropertyEntryByLength entry : properties) { String key = entry.getKey(); if (key.length() > len) continue; Pattern pattern = Pattern.compile("(^|/)(" + Pattern.quote(key) + ")/"); Matcher matcher = pattern.matcher(pathToGeneralize); pathToGeneralize = matcher.replaceAll("$1\\${" + entry.getValue() + "}/"); } return new Path(pathToGeneralize); }
From source file:com.android.emailcommon.internet.Rfc822Output.java
/** * Gets both the plain text and HTML versions of the message body. *///from w w w . j ava 2 s. c o m /*package*/ static String[] buildBodyText(Body body, int flags, boolean useSmartReply) { String[] messageBody = new String[] { null, null }; if (body == null) { return messageBody; } String text = body.mTextContent; boolean isReply = (flags & Message.FLAG_TYPE_REPLY) != 0; boolean isForward = (flags & Message.FLAG_TYPE_FORWARD) != 0; // For all forwards/replies, we add the intro text if (isReply || isForward) { String intro = body.mIntroText == null ? "" : body.mIntroText; text += intro; } if (useSmartReply) { // useSmartReply is set to true for use by SmartReply/SmartForward in EAS. // SmartForward doesn't put a break between the original and new text, so we add an LF if (isForward) { text += "\n"; } } else { String quotedText = body.mTextReply; // If there is no plain-text body, use de-tagified HTML as the text body if (quotedText == null && body.mHtmlReply != null) { quotedText = Html.fromHtml(body.mHtmlReply).toString(); } if (quotedText != null) { // fix CR-LF line endings to LF-only needed by EditText. Matcher matcher = PATTERN_ENDLINE_CRLF.matcher(quotedText); quotedText = matcher.replaceAll("\n"); } if (isReply) { if (quotedText != null) { Matcher matcher = PATTERN_START_OF_LINE.matcher(quotedText); text += matcher.replaceAll(">"); } } else if (isForward) { if (quotedText != null) { text += quotedText; } } } messageBody[INDEX_BODY_TEXT] = text; // Exchange 2003 doesn't seem to support multipart w/SmartReply and SmartForward, so // we'll skip this. Really, it would only matter if we could compose HTML replies if (!useSmartReply) { messageBody[INDEX_BODY_HTML] = getHtmlAlternate(body, useSmartReply); } return messageBody; }
From source file:org.apache.hadoop.hbase.util.ProcessBasedLocalHBaseCluster.java
private static String processLine(String line) { Matcher m = TO_REMOVE_FROM_LOG_LINES_RE.matcher(line); return m.replaceAll(""); }
From source file:org.apache.camel.converter.TimePatternConverter.java
@Converter public static long toMilliSeconds(String source) throws IllegalArgumentException { long milliseconds = 0; boolean foundFlag = false; Matcher matcher; matcher = createMatcher(NUMBERS_ONLY_STRING_PATTERN, source); if (matcher.find()) { // Note: This will also be used for regular numeric strings. // This String -> long converter will be used for all strings. milliseconds = Long.valueOf(source).longValue(); } else {//ww w . jav a2 s . co m matcher = createMatcher(REPLACEMENT_PATTERN, source); String replacedSource = matcher.replaceAll(""); if (LOG.isTraceEnabled()) { LOG.trace("Replaced original source " + source + " to " + replacedSource); } matcher = createMatcher(HOUR_REGEX_PATTERN, replacedSource); if (matcher.find()) { milliseconds = milliseconds + (3600000 * Long.valueOf(matcher.group(1)).longValue()); foundFlag = true; } matcher = createMatcher(MINUTES_REGEX_PATTERN, replacedSource); if (matcher.find()) { long minutes = Long.valueOf(matcher.group(1)).longValue(); if ((minutes > 59) && foundFlag) { throw new IllegalArgumentException( "Minutes should contain a valid value between 0 and 59: " + source); } foundFlag = true; milliseconds = milliseconds + (60000 * minutes); } matcher = createMatcher(SECONDS_REGEX_PATTERN, replacedSource); if (matcher.find()) { long seconds = Long.valueOf(matcher.group(1)).longValue(); if ((seconds > 59) && foundFlag) { throw new IllegalArgumentException( "Seconds should contain a valid value between 0 and 59: " + source); } foundFlag = true; milliseconds = milliseconds + (1000 * seconds); } // No pattern matched... initiating fallback check and conversion (if required). // The source at this point may contain illegal values or special characters if (!foundFlag) { milliseconds = Long.valueOf(source).longValue(); } } if (LOG.isTraceEnabled()) { LOG.trace("source: " + source + " milliseconds: " + milliseconds); } return milliseconds; }
From source file:ambit.data.qmrf.QMRFConverter.java
public static String replaceTags(String text) { if (text == null) return text; Matcher m = HTML_tags.matcher(text); String newText = ""; if (m.find()) { newText = m.replaceAll(""); } else {/*w w w . j a v a 2s .c om*/ newText = text; } m = CRLF.matcher(newText); if (m.find()) { newText = m.replaceAll(""); } m = ptag.matcher(newText); if (m.find()) { newText = m.replaceAll("\n"); } return newText.trim(); }
From source file:com.shishu.utility.string.StringUtil.java
/** * ???/* w w w . j av a2 s . c o m*/ * @param str * @return */ public static String replaceTab(String str) { String dest = ""; if (str != null) { Pattern p = Pattern.compile("\t|\r|\n"); Matcher m = p.matcher(str); dest = m.replaceAll(""); } return dest; }
From source file:com.avapira.bobroreader.hanabira.HanabiraParser.java
private static String replaceInternalLinkWithReference(String message) { Pattern p = Pattern// w w w . j a v a 2s .c o m .compile("https?://dobrochan\\.(?:ru|com|org)/([a-z]{1,4})/res/(\\d+)\\.xhtml(?:#i(\\d+))?"); Matcher matcher = p.matcher(message); if (matcher.groupCount() == 4) { // whole, board, thread, (opt) post return matcher.replaceAll(">>$1/$3"); //>>/board/display_id_post } else { return matcher.replaceAll(">>$1/$2"); //>>/board/thread_display_id } }
From source file:net.objectlab.kit.util.StringUtil.java
/** * Remove " and spaces from the input string. * @param inputStr//from w ww .jav a 2s. c o m * @return */ public static String prepareForNumericParsing(final String inputStr) { final Matcher matcher = PATTERN_FOR_NUM_PARSING_PREP.matcher(inputStr); return matcher.replaceAll(""); }
From source file:net.sourceforge.jaulp.string.StringUtils.java
/** * Replace each occurences from the search pattern(regex) with the given replace String of the * given input String.//w w w .ja v a 2s.com * * @param input * the input String that will be changed. * @param searchRegexPattern * the search regex pattern * @param replace * the String to replace with. * @return the resulted string */ public static String replaceEach(String input, String searchRegexPattern, String replace) { Pattern pattern = Pattern.compile(searchRegexPattern); Matcher matcher = pattern.matcher(input); return matcher.replaceAll(replace); }