List of usage examples for java.util.regex Matcher replaceAll
public String replaceAll(Function<MatchResult, String> replacer)
From source file:edu.indiana.lib.twinpeaks.util.StringUtils.java
/** * Replace all occurances of the target text with the provided replacement * text. Both target and replacement may be regular expressions - see * <code>java.util.regex.Matcher</code>. * @param text Text to modify/*from w w w. jav a2s . c om*/ * @param targetText Text to find and replace * @param newText New text * @return Updated text */ public static String replace(String text, String targetText, String newText) { Pattern pattern = Pattern.compile(targetText, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(text); return matcher.replaceAll(newText); }
From source file:com.datumbox.framework.utilities.text.cleaners.HTMLCleaner.java
protected static String removeNonTextTags(String text) { text = removeComments(text);//from ww w .j a va2s. co m Matcher m = NON_TEXT_TAGS_PATTERN.matcher(text); if (m.find()) { text = m.replaceAll(" "); } return text; }
From source file:org.exoplatform.ks.ext.impl.ForumTransformHTML.java
public static String cleanHtmlCode(String sms, List<String> bbcs) { if (sms == null || sms.trim().length() <= 0) return ""; sms = StringUtils.replace(sms, "\n", " "); // clean bbcode List<String> bbcList = new ArrayList<String>(); bbcList.addAll(bbcs);/* w w w .j a v a2 s . c o m*/ for (String bbc : bbcs) { bbcList.add(bbc.toLowerCase()); } int lastIndex = 0; int tagIndex = 0; String start, end; for (String bbc : bbcList) { start = "[" + bbc; end = "[/" + bbc + "]"; lastIndex = 0; tagIndex = 0; while ((tagIndex = sms.indexOf(start, lastIndex)) != -1) { lastIndex = tagIndex + 1; try { int clsIndex = sms.indexOf(end, tagIndex); String content = sms.substring(tagIndex, clsIndex); String content_ = content.substring(content.indexOf("]") + 1); sms = StringUtils.replace(sms, content + end, content_); } catch (Exception e) { continue; } } } sms = StringUtils.replace(sms, "[U]", ""); sms = StringUtils.replace(sms, "[/U]", ""); sms = StringUtils.replace(sms, "[u]", ""); sms = StringUtils.replace(sms, "[/u]", ""); // Clean html code String scriptregex = "<(script|style)[^>]*>[^<]*</(script|style)>"; Pattern p1 = Pattern.compile(scriptregex, Pattern.CASE_INSENSITIVE); Matcher m1 = p1.matcher(sms); sms = m1.replaceAll(""); String tagregex = "<[^>]*>"; Pattern p2 = Pattern.compile(tagregex); Matcher m2 = p2.matcher(sms); sms = m2.replaceAll(""); String multiplenewlines = "(\\n{1,2})(\\s*\\n)+"; sms = sms.replaceAll(multiplenewlines, "$1"); return sms; }
From source file:com.datumbox.framework.utilities.text.cleaners.HTMLCleaner.java
public static String removeNonTextTagsAndAttributes(String text) { text = removeNonTextTags(text);//from ww w .j ava2 s. c o m Matcher m = REMOVE_ATTRIBUTES_PATTERN.matcher(text); if (m.find()) { text = m.replaceAll("<$1$2>"); } text = StringEscapeUtils.unescapeHtml4(text); return text; }
From source file:com.gizwits.gizdataaccesssdkdemo.activitys.SaveActivity.java
/** * ?//from w w w. j a v a 2s. com * * @param str * * @return String ?? * */ public static String replaceBlank(String str) { String dest = ""; if (str != null) { Pattern p = Pattern.compile("\\s*|\t|\r|\n"); Matcher m = p.matcher(str); dest = m.replaceAll(""); } return dest; }
From source file:org.loklak.susi.SusiPhrase.java
public static String normalizeExpression(String s) { s = s.toLowerCase().replaceAll("\\#", " "); Matcher m; while ((m = dspace.matcher(s)).find()) s = m.replaceAll(" "); // to be considered: https://en.wikipedia.org/wiki/Wikipedia:List_of_English_contractionst int p = -1;/* w w w.j a v a2 s . com*/ while ((p = s.toLowerCase().indexOf("it's ")) >= 0) s = s.substring(0, p + 2) + " is " + s.substring(p + 5); while ((p = s.toLowerCase().indexOf("what's ")) >= 0) s = s.substring(0, p + 4) + " is " + s.substring(p + 7); return s; }
From source file:com.jwebmp.core.utilities.EscapeChars.java
/** * Disable all script tags/*w ww . jav a 2 s . c o m*/ * * @param aText * * @return */ public static String forScriptTagsOnly(String aText) { String result; Matcher matcher = EscapeChars.SCRIPT.matcher(aText); result = matcher.replaceAll(">SCRIPT<"); matcher = EscapeChars.SCRIPT_END.matcher(result); result = matcher.replaceAll(">/SCRIPT<"); return result; }
From source file:com.linkedin.databus.core.util.StringUtils.java
/** * Strip username/password information from the JDBC DB uri to be used for logging * @param uri the JDBC URI to sanitize * @return the sanitized DB URI/*from w w w .j ava 2 s .c om*/ */ public static String sanitizeDbUri(String uri) { String result = uri; Matcher m = ORA_JDBC_URI_PATTERN.matcher(uri); if (m.matches()) { result = m.group(1) + "*/*" + m.group(4); } else if (uri.startsWith("jdbc:mysql:")) { Matcher m1 = MYSQL_JDBC_PATTERN1.matcher(result); Matcher m2 = MYSQL_JDBC_PATTERN2.matcher(result); if (m1.find()) { result = m1.replaceAll("($1*)"); } else if (m2.find()) { result = m2.replaceAll("$1*"); } } return result; }
From source file:burrito.util.StringUtils.java
private static String stripScripts(String string) { Matcher m = scriptPattern.matcher(string); return m.replaceAll(""); }
From source file:hu.webhejj.commons.text.StringUtils.java
/** @return a <code>String</code> with multiple consecutive spaces replaced with a single space. */ public static String removeDoubleSpaces(String string) { Matcher matcher = multiSpacePattern.matcher(string); return matcher.replaceAll(" "); }