List of usage examples for java.util.regex Pattern DOTALL
int DOTALL
To view the source code for java.util.regex Pattern DOTALL.
Click Source Link
From source file:org.kie.server.integrationtests.shared.KieServerBaseIntegrationTest.java
protected static void assertResultNotContainingStringRegex(String result, String regex) { assertFalse("Regex '" + regex + "' matches result string '" + result + "'!", Pattern.compile(regex, Pattern.DOTALL).matcher(result).matches()); }
From source file:org.apache.asterix.test.aql.TestExecutor.java
public void runScriptAndCompareWithResultRegexAdm(File scriptFile, File expectedFile, File actualFile) throws Exception { StringWriter actual = new StringWriter(); StringWriter expected = new StringWriter(); IOUtils.copy(new FileInputStream(actualFile), actual, StandardCharsets.UTF_8); IOUtils.copy(new FileInputStream(expectedFile), expected, StandardCharsets.UTF_8); Pattern pattern = Pattern.compile(expected.toString(), Pattern.DOTALL | Pattern.MULTILINE); if (!pattern.matcher(actual.toString()).matches()) { throw new Exception("Result for " + scriptFile + ": actual file did not match expected result"); }//from w ww . j a va 2 s. c om }
From source file:mobi.jenkinsci.server.core.net.ProxyUtil.java
private String replaceLinks(final String linkPattern, final int linkIndex, final String newLinkPrefix, final String remoteBasePath, final String content) { log.debug("Rewriting links to basePath " + remoteBasePath); final boolean isUrlEncodingNeeded = newLinkPrefix.indexOf('?') >= 0; final Pattern pattern = Pattern.compile(linkPattern, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); final Matcher m = pattern.matcher(content); // determines if the link is absolute final StringBuffer buffer = new StringBuffer(); int lastEnd = 0; while (m.find()) { final String link = m.group(linkIndex).trim(); if (link.startsWith("data")) { continue; }/* ww w . ja va2 s .co m*/ if (!isFullLinkWithProtocol(link)) { String newURI = getRelativeLink(newLinkPrefix, remoteBasePath, isUrlEncodingNeeded, link); buffer.append(getSubstringBetweenLinks(linkIndex, content, m, lastEnd)); buffer.append(newURI.trim()); lastEnd = m.end(linkIndex); } } buffer.append(content.substring(lastEnd)); return buffer.toString(); }
From source file:de.undercouch.bson4jackson.BsonParser.java
/** * Converts a BSON regex pattern string to a combined value of Java flags that * can be used in {@link Pattern#compile(String, int)} * @param pattern the regex pattern string * @return the Java flags//from www . j a va2 s. co m * @throws JsonParseException if the pattern string contains a unsupported flag */ protected int regexStrToFlags(String pattern) throws JsonParseException { int flags = 0; for (int i = 0; i < pattern.length(); ++i) { char c = pattern.charAt(i); switch (c) { case 'i': flags |= Pattern.CASE_INSENSITIVE; break; case 'm': flags |= Pattern.MULTILINE; break; case 's': flags |= Pattern.DOTALL; break; case 'u': flags |= Pattern.UNICODE_CASE; break; case 'l': case 'x': //unsupported break; default: throw new JsonParseException("Invalid regex", getTokenLocation()); } } return flags; }
From source file:opennlp.tools.similarity.apps.utils.Utils.java
public static String stripScriptTags(String text) { Pattern p = java.util.regex.Pattern.compile("\\<SCRIPT.*?</SCRIPT>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); Matcher matcher = p.matcher(text); String tmp = matcher.replaceAll(""); return tmp;//from w w w . j a v a 2 s .co m }
From source file:opennlp.tools.similarity.apps.utils.Utils.java
public static String stripNoScriptTags(String text) { Pattern p = java.util.regex.Pattern.compile("\\<NOSCRIPT.*?</NOSCRIPT>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); Matcher matcher = p.matcher(text); String tmp = matcher.replaceAll(""); return tmp;/* w w w. j a v a2 s .c o m*/ }
From source file:com.eviware.soapui.support.Tools.java
public static boolean isSimilar(String expected, String real, char wildcard) throws ComparisonFailure { // expected == wildcard matches all if (!expected.equals(String.valueOf(wildcard))) { StringBuilder sb = new StringBuilder(); if (expected.startsWith(String.valueOf(wildcard))) { sb.append(".*"); }/*from www. ja v a2 s . c o m*/ boolean first = true; for (String token : expected.split(Pattern.quote(String.valueOf(wildcard)))) { if (token.isEmpty()) { continue; } if (!first) { sb.append(".*"); } first = false; sb.append(Pattern.quote(token)); } if (expected.endsWith(String.valueOf(wildcard))) { sb.append(".*"); } if (!Pattern.compile(sb.toString(), Pattern.DOTALL).matcher(real).matches()) { return false; } } return true; }
From source file:org.sakaiproject.tool.assessment.qti.util.XmlUtil.java
public static String processFormattedText(Log log, String value) { if (StringUtils.isEmpty(value)) { return value; }//w w w .j a v a 2s . c o m StringBuilder alertMsg = new StringBuilder(); String finalValue = ""; Matcher matcher = M_htmlPattern.matcher(value); boolean hasHtmlPattern = false; int index = 0; StringBuilder textStringBuilder = new StringBuilder(); String tmpText = ""; if (M_goodTagsPatterns == null || M_goodCloseTagsPatterns == null) { M_goodTagsPatterns = new Pattern[M_goodTags.length]; M_goodCloseTagsPatterns = new Pattern[M_goodTags.length]; for (int i = 0; i < M_goodTags.length; i++) { M_goodTagsPatterns[i] = Pattern.compile(".*<\\s*" + M_goodTags[i] + "(\\s+.*>|>|/>).*", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL); M_goodCloseTagsPatterns[i] = Pattern.compile("<\\s*/\\s*" + M_goodTags[i] + "(\\s.*>|>)", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL); } } while (matcher.find()) { hasHtmlPattern = true; tmpText = value.substring(index, matcher.start()); textStringBuilder.append(convertoLTGT(tmpText)); String group = matcher.group(); boolean isGoodTag = false; for (int i = 0; i < M_goodTags.length; i++) { if (M_goodTagsPatterns[i].matcher(group).matches() || M_goodCloseTagsPatterns[i].matcher(group).matches()) { textStringBuilder.append(group); isGoodTag = true; break; } } if (!isGoodTag) { textStringBuilder.append(convertoLTGT(group)); } index = matcher.end(); } textStringBuilder.append(convertoLTGT(value.substring(index))); if (hasHtmlPattern) { finalValue = formattedText.processFormattedText(textStringBuilder.toString(), alertMsg); } else { finalValue = formattedText.processFormattedText(convertoLTGT(value), alertMsg); } if (alertMsg.length() > 0) { log.debug(alertMsg.toString()); } return finalValue; }
From source file:com.hexidec.ekit.component.HTMLUtilities.java
private static String convertPointsToCm(String html) { StringBuffer sb = new StringBuffer(); Pattern pTag = Pattern.compile("(<.+?style=\")(.+?)(\".*?>)", Pattern.DOTALL); Pattern pNumber = Pattern.compile("\\d+(?:\\.\\d*)"); Matcher mTag = pTag.matcher(html); while (mTag.find()) { StringBuilder sbStyle = new StringBuilder(mTag.group(1)); Map<String, String> mapStyle = DocumentUtil.styleToMap(mTag.group(2)); for (Map.Entry<String, String> e : mapStyle.entrySet()) { String key = e.getKey(); String value = e.getValue(); if (pNumber.matcher(value).matches()) { value = LengthUnit.convertTo(Float.parseFloat(value), "cm"); }//from ww w. j a va2 s . c om sbStyle.append(key + ": " + value + "; "); } sbStyle.append(mTag.group(3)); mTag.appendReplacement(sb, Matcher.quoteReplacement(sbStyle.toString())); } mTag.appendTail(sb); return sb.toString(); }
From source file:com.qumoon.commons.web.HTMLInputChecker.java
protected String validateEntities(String s) { // validate entities throughout the string Pattern p = Pattern.compile("&([^&;]*)(?=(;|&|$))"); Matcher m = p.matcher(s);//from w w w . j a v a 2 s . c o m StringBuffer buf = new StringBuffer(); if (m.find()) { String one = m.group(1); // ([^&;]*) String two = m.group(2); // (?=(;|&|$)) appendReplacement(m, buf, checkEntity(one, two)); } m.appendTail(buf); s = buf.toString(); // validate quotes outside of tags p = Pattern.compile("(>|^)([^<]+?)(<|$)", Pattern.DOTALL); m = p.matcher(s); buf = new StringBuffer(); if (m.find()) { String one = m.group(1); // (>|^) String two = m.group(2); // ([^<]+?) String three = m.group(3); // (<|$) appendReplacement(m, buf, one + two.replaceAll("\"", """) + three); } m.appendTail(buf); return s; }