List of usage examples for java.util.regex Matcher replaceAll
public String replaceAll(Function<MatchResult, String> replacer)
From source file:de.shadowhunt.subversion.internal.ResourcePropertyUtils.java
static InputStream escapedInputStream(final InputStream inputStream) throws IOException { final String rawData = IOUtils.toString(inputStream, UTF8); inputStream.close();// w ww . j av a 2 s . com final Matcher matcher = PATTERN.matcher(rawData); final String escapedData = matcher.replaceAll("<$1$2$3:$4" + MARKER + "$5$6$7>"); return IOUtils.toInputStream(escapedData, UTF8); }
From source file:Main.java
public static String getNoTagsTrimText(String xml) { Matcher m = tagPattern.matcher(xml); if (!m.find()) { return xml; }//from w ww . j a v a2 s. com String replaced = m.replaceAll(""); replaced = replaced.replaceAll("\\r\\n", ""); replaced = replaced.replaceAll("\\n", ""); replaced = replaced.replaceAll("\\t", ""); replaced = replaced.replaceAll("\\s+", " "); replaced = replaced.trim(); return replaced; }
From source file:com.gs.obevo.util.DAStringUtil.java
/** * Replaces all forms and lengths of whitespace w/ a single space so that we can subsequently calculate the hash of * a string based solely on the textual content. * Note that for practical reasons, we treat this as a 99.99999% accurate thing, i.e. we do not try to be smart * enough where we only parse out whitespace that is not inside quotes (i.e. if it is an actual string literal). * (Though if we can get it to 100% one day, I'm all for it. But in practice, this should be good enough) *///from w ww . j ava 2 s .co m public static String normalizeWhiteSpaceFromString(String content) { if (content == null) { return null; } final Matcher matcher = pattern.matcher(content); final String s = matcher.replaceAll(" ").trim(); if (s.isEmpty()) { return null; } return s; }
From source file:Main.java
/** * Replaces a tag given by a tagname in an xmlstring. * /* w w w .j a va 2 s.c om*/ * @param tagname Name of the tag to be removed * @param xmlstring XmlString to be modified * @return modified XmlString */ public static String removeTag(String tagname, String xmlstring) { if (!patterns.containsKey(tagname)) { String regex = "(\\<" + tagname + ">.+?\\</" + tagname + ">)"; Pattern pattern = Pattern.compile(regex, Pattern.DOTALL | Pattern.MULTILINE); patterns.put(tagname, pattern); } Matcher matcher = patterns.get(tagname).matcher(xmlstring); if (matcher.find()) { xmlstring = matcher.replaceAll(""); } return xmlstring; }
From source file:com.benfante.minimark.util.TextFilterUtils.java
public static String filterTypoCode(String txt) { String result = null;/*from w w w. j a v a 2 s. c o m*/ Matcher matcher = replaceIncompleteTypoCodePattern.matcher(txt); result = matcher.replaceAll("<pre name=\"code\" class=\"xml\">$1</pre>"); matcher = replaceTypoCodePattern.matcher(result); result = matcher.replaceAll("<pre name=\"code\"$1>$2</pre>"); matcher = replaceLangPattern.matcher(result); result = matcher.replaceAll("class=$1"); return result; }
From source file:fridgegameinstaller.MCJsonConf.java
public static void getJson(String path, int mb) throws IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet("http://api.fridgegame.com/mcconf/Fridgegame.json"); CloseableHttpResponse response1 = httpclient.execute(httpGet); try {/*from ww w . j a va2s.c om*/ System.out.println(httpGet.toString()); System.out.println(response1.getStatusLine()); BufferedReader br = new BufferedReader(new InputStreamReader(response1.getEntity().getContent())); String a; String output = ""; while ((a = br.readLine()) != null) { output += a + "\n"; } System.out.println(output); try { JSONObject json = new JSONObject(output); String mcArgs = json.getString("minecraftArguments"); String regex = "(-Xmx[^ ]*)"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(mcArgs); String newArgs = m.replaceAll("-Xmx" + mb + "M"); json.put("minecraftArguments", newArgs); FileWriter file = new FileWriter(path); try { file.write(json.toString()); } catch (IOException e) { e.printStackTrace(); } finally { file.flush(); file.close(); } } catch (JSONException e) { } } finally { response1.close(); } }
From source file:Main.java
/** * Helper function for decode XML entities. * * @param str The XML-encoded String to decode. * @return An XML-decoded String.//w w w .j a va 2 s . c o m */ public static String decode(String str) { if (str == null) { return null; } Matcher gtmatcher = encgt.matcher(str); if (gtmatcher.matches()) { str = gtmatcher.replaceAll(">"); } Matcher ltmatcher = enclt.matcher(str); if (ltmatcher.matches()) { str = ltmatcher.replaceAll("<"); } Matcher quotMatcher = encQuot.matcher(str); if (quotMatcher.matches()) { str = quotMatcher.replaceAll("\""); } Matcher ampMatcher = encAmp.matcher(str); if (ampMatcher.matches()) { str = ampMatcher.replaceAll("&"); } return str; }
From source file:com.qdum.llhb.common.utils.StringUtils.java
/** * ?// ww w . jav a2s. co m * @param str * @return */ 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:cn.org.citycloud.srdz.utils.StringUtils.java
/** * ?HTML//from w w w . j a v a 2 s . c o m */ public static String replaceHtml(String html) { if (isBlank(html)) { return ""; } String regEx = "<.+?>"; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(html); String s = m.replaceAll(""); return s; }
From source file:Main.java
public static String cleanXmlNulls(String xml) { Pattern pattern = null;//from w w w .j a va 2 s . c om Matcher matcher = null; pattern = Pattern.compile("[\\000]*"); matcher = pattern.matcher(xml); if (matcher.find()) { xml = matcher.replaceAll(""); } return xml; }