List of usage examples for java.util.regex Matcher replaceAll
public String replaceAll(Function<MatchResult, String> replacer)
From source file:apps.ParsedPost.java
private static String replace(String src, String pat, String repl, boolean bIgnoreCase) { Pattern p = bIgnoreCase/*from www . j av a 2 s . co m*/ ? Pattern.compile(pat, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL) : Pattern.compile(pat, Pattern.MULTILINE | Pattern.DOTALL); Matcher m = p.matcher(src); return m.replaceAll(repl); }
From source file:com.pfarrell.utils.misc.TextTools.java
/** * manually fix the dumb double dot that Tomcat seems to create. * @param url input string that may have double dot * @return cleaned up string./* w w w .j av a2 s . c o m*/ */ public static String fixEvilDoubleDot(String url) { Preconditions.checkNotNull(url); String rval = url; Matcher m = doubleDotPattern.matcher(url); if (m.find()) { rval = m.replaceAll("digital\\.com"); } return rval; }
From source file:com.android.email.mail.transport.Rfc822Output.java
static String buildBodyText(Context context, Message message, boolean appendQuotedText) { Body body = Body.restoreBodyWithMessageId(context, message.mId); if (body == null) { return null; }/*from ww w .ja va 2 s . c om*/ String text = body.mTextContent; int flags = message.mFlags; boolean isReply = (flags & Message.FLAG_TYPE_REPLY) != 0; boolean isForward = (flags & Message.FLAG_TYPE_FORWARD) != 0; String intro = body.mIntroText == null ? "" : body.mIntroText; if (!appendQuotedText) { // appendQuotedText is set to false for use by SmartReply/SmartForward in EAS. // SmartReply doesn't appear to work properly, so we will still add the header into // the original message. // SmartForward doesn't put any kind of break between the original and the new text, // so we add a CRLF if (isReply) { text += intro; } else if (isForward) { text += "\r\n"; } return text; } String quotedText = body.mTextReply; 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) { text += intro; if (quotedText != null) { Matcher matcher = PATTERN_START_OF_LINE.matcher(quotedText); text += matcher.replaceAll(">"); } } else if (isForward) { text += intro; if (quotedText != null) { text += quotedText; } } return text; }
From source file:com.fengduo.bee.commons.util.StringFormatter.java
public static String matcherRegex(String s, String regex, boolean needTrim) { if (StringUtils.isBlank(s)) { return StringUtils.EMPTY; }/*from w ww. j ava 2s .co m*/ Pattern p = Pattern.compile(regex); Matcher m = p.matcher(s); return needTrim ? m.replaceAll(StringUtils.EMPTY).trim() : m.replaceAll(StringUtils.EMPTY); }
From source file:com.reizes.shiva.utils.AddrUtil.java
/** * ? ? 0, 1,2 (common? // ?)//from w ww . ja v a 2 s. co m * @param addr * @return */ public static String[] splitRoadAddr(String addr) { String[] addrs = new String[5]; if (addr != null) { Matcher matcher = PATTERN_NORMALIZE_ROAD_ADDR.matcher(addr); if (matcher.find()) { addrs[0] = StringUtil.normalize(matcher.group(1)); // // addrs[1] = StringUtil.normalize(matcher.group(2)); // ??//? - ? ??//?? ? . addrs[2] = StringUtil.normalize(StringUtils.join(StringUtils.split(matcher.group(3), ' '))); // ? - ?? ? . addrs[3] = StringUtil .normalize(matcher.group(4) + (matcher.group(5) != null ? "-" + matcher.group(5) : "")); // String invalid = StringUtil.normalize(matcher.group(6)); // / .. ?? ? . if (invalid != null) { addrs[3] = null; } // 2012.11.8 addr3 String addr3 = StringUtil.normalize(matcher.group(7)); if (addr3 != null) { Matcher matcher2 = PATTERN_INVALID_ADDR3.matcher(addr3); // addr3? if (matcher2.find()) { addr3 = StringUtil.normalize(matcher2.replaceAll("")); } addrs[4] = StringUtil.normalize(addr3); // addr3 } } } return addrs; }
From source file:com.webarch.common.lang.StringSeriesTools.java
/** * ????//from ww w . jav a 2 s . co m * * @param sourceStr * @param regex * @param replacement ??? * @return */ public static String replaceAllMatch(final String sourceStr, final String regex, final String replacement) { Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(sourceStr); String source = matcher.replaceAll(replacement); return source; }
From source file:org.eclipse.buckminster.jnlp.MaterializationUtils.java
/** * Generalize <code>IPath</code> * //from w w w. ja v a 2s . 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) + ")/"); //$NON-NLS-1$ //$NON-NLS-2$ Matcher matcher = pattern.matcher(pathToGeneralize); pathToGeneralize = matcher.replaceAll("$1\\${" + entry.getValue() + "}/"); //$NON-NLS-1$ //$NON-NLS-2$ } return new Path(pathToGeneralize); }
From source file:com.sun.socialsite.util.UtilitiesModel.java
private static String replace(String string, Pattern pattern, String replacement) { Matcher m = pattern.matcher(string); return m.replaceAll(replacement); }
From source file:fr.paris.lutece.plugins.workflow.modules.notifygru.service.TaskNotifyGru.java
/** * Removes the tags.// w ww.j av a 2 s . c om * * @param string the string * @return the string */ public static String removeTags(String string) { if ((string == null) || (string.length() == 0)) { return string; } Matcher m = REMOVE_TAGS.matcher(string); return m.replaceAll(""); }
From source file:com.mail163.email.mail.transport.Rfc822Output.java
static String buildBodyText(Context context, Message message, boolean appendQuotedText) { Body body = Body.restoreBodyWithMessageId(context, message.mId); if (body == null) { return null; }/*from w w w. j av a2s . c om*/ String text = body.mTextContent; int flags = message.mFlags; 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 (!appendQuotedText) { // appendQuotedText is set to false 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"; } return text; } String quotedText = body.mTextReply; 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"); } //================2013.7.3================ String quotedHtmlText = body.mHtmlReply; if (quotedHtmlText != null) { // fix CR-LF line endings to LF-only needed by EditText. Matcher matcher = PATTERN_ENDLINE_CRLF.matcher(quotedHtmlText); quotedHtmlText = matcher.replaceAll("\n"); } isContentType = false; if (isReply) { if (quotedText != null) { Matcher matcher = PATTERN_START_OF_LINE.matcher(quotedText); text += matcher.replaceAll(""); } else if (quotedHtmlText != null) { Matcher matcher = PATTERN_START_OF_LINE.matcher(quotedHtmlText); text += matcher.replaceAll(""); isContentType = true; } } else if (isForward) { if (quotedText != null) { text += quotedText; } else if (quotedHtmlText != null) { text += quotedHtmlText; isContentType = true; } } //================2013.7.3================ return text; }