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:com.geecko.QuickLyric.MainActivity.java
private String getIdUrl(String extra) { final Pattern urlPattern = Pattern.compile( "(?:^|[\\W])((ht|f)tp(s?):\\/\\/|www\\.)" + "(([\\w\\-]+\\.){1,}?([\\w\\-.~]+\\/?)*" + "[\\p{Alnum}.,%_=?&#\\-+()\\[\\]\\*$~@!:/{};']*)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); if (!(extra == null || extra.isEmpty())) { Matcher matcher = urlPattern.matcher(extra); if (matcher.find()) return extra.substring(matcher.start(), matcher.end()); }//w ww. j ava 2 s . com return null; }
From source file:opennlp.tools.similarity.apps.utils.Utils.java
public static String stripHTMLMultiLine(String text) { Pattern p = java.util.regex.Pattern.compile("\\<.*?>", Pattern.DOTALL); Matcher matcher = p.matcher(text); String tmp = matcher.replaceAll(""); return tmp;/*from w ww . j a v a2 s . c o m*/ }
From source file:opennlp.tools.similarity.apps.utils.Utils.java
public static String stripHTMLCommentsMultiLine(String text) { Pattern p = java.util.regex.Pattern.compile("\\<!--.*?-->", Pattern.DOTALL); Matcher matcher = p.matcher(text); String tmp = matcher.replaceAll(""); return tmp;/* w w w. ja v a 2 s . co m*/ }
From source file:com.hexidec.ekit.component.HTMLUtilities.java
public static String ensureInlineContent(String s) { if (StringUtils.isEmpty(s)) { return s; }/*from w ww. j ava 2 s. c o m*/ List<String> inlineTags = ExtendedHTMLDocument.getAcceptedInlineTags(); StringBuffer sb = new StringBuffer(); Pattern p = Pattern.compile("</?(\\w+).*?>", Pattern.DOTALL); Matcher m = p.matcher(s); while (m.find()) { String replacement = ""; if (inlineTags.contains(m.group(1).toLowerCase())) { replacement = Matcher.quoteReplacement(m.group()); } m.appendReplacement(sb, replacement); } m.appendTail(sb); return sb.toString(); }
From source file:com.qmetry.qaf.automation.ui.selenium.AssertionService.java
public static boolean seleniumEquals(String expectedPattern, String actual) { if (actual.startsWith("regexp:") || actual.startsWith("regex:") || actual.startsWith("regexpi:") || actual.startsWith("regexi:")) { // swap 'em String tmp = actual;/*from w w w.jav a2s.c o m*/ actual = expectedPattern; expectedPattern = tmp; } Boolean b; b = handleRegex("regexp:", expectedPattern, actual, 0); if (b != null) { return b.booleanValue(); } b = handleRegex("regex:", expectedPattern, actual, 0); if (b != null) { return b.booleanValue(); } b = handleRegex("regexpi:", expectedPattern, actual, Pattern.CASE_INSENSITIVE); if (b != null) { return b.booleanValue(); } b = handleRegex("regexi:", expectedPattern, actual, Pattern.CASE_INSENSITIVE); if (b != null) { return b.booleanValue(); } if (expectedPattern.startsWith("exact:")) { String expectedExact = expectedPattern.replaceFirst("exact:", ""); if (!expectedExact.equals(actual)) { System.out.println("expected " + actual + " to match " + expectedPattern); return false; } return true; } String expectedGlob = expectedPattern.replaceFirst("glob:", ""); expectedGlob = expectedGlob.replaceAll("([\\]\\[\\\\{\\}$\\(\\)\\|\\^\\+.])", "\\\\$1"); expectedGlob = expectedGlob.replaceAll("\\*", ".*"); expectedGlob = expectedGlob.replaceAll("\\?", "."); if (!Pattern.compile(expectedGlob, Pattern.DOTALL).matcher(actual).matches()) { System.out.println("expected \"" + actual + "\" to match glob \"" + expectedPattern + "\" (had transformed the glob into regexp \"" + expectedGlob + "\""); return false; } return true; }
From source file:org.apache.maven.plugin.cxx.CMakeMojo.java
protected void updateOrCreateCMakeDependenciesFile(List aiDependenciesLib, boolean bMavenDependencies) { String dependencieFile = (bMavenDependencies ? cmakeMavenDependenciesFile : cmakeDependenciesFile); String fullDependenciesFile = dependencieFile; File file = new File(dependencieFile); if (!file.isAbsolute()) { // $FB always use unix path separator with cmake even under windows ! fullDependenciesFile = getProjectDir() + "/" + dependencieFile; }//from ww w.j a v a2 s. c o m file = new File(fullDependenciesFile); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { getLog().error(dependencieFile + " script can't be created at " + file.getAbsolutePath()); return; } } // check file content InputStream dependenciesStream = null; String content = new String(); try { dependenciesStream = new FileInputStream(file); content = IOUtils.toString(dependenciesStream, "UTF8"); } catch (IOException e) { // shall not happen since file has been created getLog().error(dependencieFile + " script can't be opened at " + file.getAbsolutePath()); } finally { getLog().debug("close input stream at reading"); IOUtils.closeQuietly(dependenciesStream); } String beginDepsPattern = (bMavenDependencies ? (isDebugBuild() ? "# BEGIN MAVEN_DEBUG_DEPENDENCIES" : "# BEGIN MAVEN_OPTIMIZED_DEPENDENCIES") : "# BEGIN CMAKE_DEPENDENCIES"); String endDepsPattern = (bMavenDependencies ? (isDebugBuild() ? "# END MAVEN_DEBUG_DEPENDENCIES" : "# END MAVEN_OPTIMIZED_DEPENDENCIES") : "# END CMAKE_DEPENDENCIES"); String beginIncPattern = "# BEGIN MAVEN_INCLUDE_ROOTS"; String endIncPattern = "# END MAVEN_INCLUDE_ROOTS"; // reset file content if needed if (StringUtils.isEmpty(content) || content.indexOf(beginDepsPattern) == -1) { getLog().info(file.getAbsolutePath() + " content full update"); try { dependenciesStream = getClass() .getResourceAsStream((bMavenDependencies ? "/cmake-cpp-project/CMakeMavenDependencies.txt" : "/cmake-cpp-project/CMakeDependencies.txt")); content = IOUtils.toString(dependenciesStream, "UTF8"); } catch (IOException e) { getLog().error(dependencieFile + " default content not found "); } finally { getLog().debug("close input stream at full update"); IOUtils.closeQuietly(dependenciesStream); } } // update file content String simpleIndentation = "\n "; String doubleIndentation = "\n "; Iterator itDeps = aiDependenciesLib.iterator(); StringBuilder allDepsBuilder = new StringBuilder( (bMavenDependencies ? doubleIndentation : simpleIndentation)); while (itDeps.hasNext()) { String dep = (String) itDeps.next(); if (bMavenDependencies) { String externalDep = generalizeDependencyFileName(dep, true); allDepsBuilder.append("target_link_libraries(${target} " + (isDebugBuild() ? "debug " : "optimized ") + externalDep + ")" + doubleIndentation); } else { String cmakeDep = generalizeDependencyFileName(dep, false); allDepsBuilder.append("# If a \"" + cmakeDep + "\" target has been define, this means we are building " + "an amalgamed cmake project" + simpleIndentation + "# but maven dependencies can be used too" + simpleIndentation + "if(TARGET " + cmakeDep + ")" + doubleIndentation + "message(\"Adding direct " + cmakeDep + " cmake dependencies to target '${target}'\")" + doubleIndentation + "target_link_libraries(${target} " + cmakeDep + ")" + simpleIndentation + "endif()" + simpleIndentation); } } // adding additionalIncludeRoots in cmake maven dependencies file StringBuilder addIncsBuilder = new StringBuilder(doubleIndentation); if (bMavenDependencies && null != additionalIncludeRoots) { addIncsBuilder.append("include_directories( " + doubleIndentation); for (String includeRoot : additionalIncludeRoots) { addIncsBuilder.append("\"" + includeRoot + "\"" + doubleIndentation); } addIncsBuilder.append(")" + doubleIndentation); for (String includeRoot : additionalIncludeRoots) { addIncsBuilder.append( "message(\"Adding '" + includeRoot + "' additional include root.\")" + doubleIndentation); } } getLog().debug(dependencieFile + " depfile was : " + content); String allDeps = Matcher.quoteReplacement(allDepsBuilder.toString()); //.replace( "$", "\\$" ); // Matcher replaceAll() is a bit rigid ! getLog().debug(dependencieFile + " injected dependency will be : " + allDeps); // regexp multi-line replace, see http://stackoverflow.com/questions/4154239/java-regex-replaceall-multiline Pattern p1 = Pattern.compile(beginDepsPattern + ".*" + endDepsPattern, Pattern.DOTALL); Matcher m1 = p1.matcher(content); content = m1.replaceAll(beginDepsPattern + allDeps + endDepsPattern); if (bMavenDependencies && null != additionalIncludeRoots) { String addIncs = Matcher.quoteReplacement(addIncsBuilder.toString()); //.replace( "$", "\\$" ); // Matcher replaceAll() is a bit rigid ! getLog().debug(dependencieFile + " injected includes Roots will be : " + addIncs); Pattern p2 = Pattern.compile(beginIncPattern + ".*" + endIncPattern, Pattern.DOTALL); Matcher m2 = p2.matcher(content); content = m2.replaceAll(beginIncPattern + addIncs + endIncPattern); } getLog().debug(dependencieFile + " depfile now is : " + content); OutputStream outStream = null; try { outStream = new FileOutputStream(file); IOUtils.write(content, outStream, "UTF8"); } catch (IOException e) { getLog().error( dependencieFile + " script can't be written at " + file.getAbsolutePath() + e.toString()); } finally { getLog().debug("close output stream at update"); IOUtils.closeQuietly(outStream); } }
From source file:com.hexidec.ekit.component.HTMLUtilities.java
public static String removeTag(String str, Tag tag) { Pattern pattern = Pattern.compile("</?" + tag + "\\b.*?>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); return pattern.matcher(str).replaceAll(""); }
From source file:com.hexidec.ekit.component.HTMLUtilities.java
public static boolean contemTag(String str, Tag tag) { Pattern p = Pattern.compile("<" + tag + "\\b.*?>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); return p.matcher(str).find(); }
From source file:com.hexidec.ekit.component.HTMLUtilities.java
public static String getConteudoTag(String html, Tag tag) { Pattern p = Pattern.compile("<" + tag + "\\b.*?>(.*?)</" + tag + "\\s*>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(html);/* w w w . j ava2s. co m*/ if (m.find()) { return m.group(1); } return null; }