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.android.dialer.lookup.whitepages.WhitePagesApi.java
private static String httpGet(String url) throws IOException { HttpGet get = new HttpGet(url); if (mCookie != null) { get.setHeader("Cookie", COOKIE + "=" + mCookie); }// ww w. j a v a 2s . com String output = LookupUtils.httpGet(get); // If we can find a new cookie, use it Pattern p = Pattern.compile(COOKIE_REGEX, Pattern.DOTALL); Matcher m = p.matcher(output); if (m.find()) { mCookie = m.group(1).trim(); Log.v(TAG, "Got new cookie"); } // If we hit a page with a <meta> refresh and the error URL, reload. If // this results in infinite recursion, then whatever. The thread is // killed after 10 seconds. p = Pattern.compile("<meta[^>]+http-equiv=\"refresh\"", Pattern.DOTALL); m = p.matcher(output); if (m.find() && output.contains("distil_r_captcha.html")) { Log.w(TAG, "Got <meta> refresh. Reloading..."); return httpGet(url); } return output; }
From source file:com.androzic.plugin.tracker.SMSReceiver.java
private boolean parseFlexMode(String text, Tracker tracker) { Log.w(TAG, "parseFlexMode"); //Pattern pattern = Pattern.compile("(-?\\d{1,3},\\d{5,6}[SN]?).+(-?\\d{1,3},\\d{5,6}[WE]?)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Pattern pattern = Pattern.compile("(-?\\d+(?:\\.|,)\\d{5,6}[SN]?)[^\\d-]+(-?\\d+(?:\\.|,)\\d{5,6}[WE]?)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher m = pattern.matcher(text); if (!m.find()) return false; Log.w(TAG, "parseFlexMode - match " + m.group(0)); String latitude = m.group(1); String longitude = m.group(2); double coords[] = CoordinateParser.parse(latitude + " " + longitude); if (Double.isNaN(coords[0]) || Double.isNaN(coords[1])) return false; if (coords[0] < -180 || coords[0] > 180 || coords[1] < -180 || coords[1] > 180) return false; tracker.latitude = coords[0];/*from w w w. ja va 2 s . com*/ tracker.longitude = coords[1]; pattern = Pattern.compile("speed[^\\d]{0,2}(\\d{1,3}(\\.\\d{1,4})?)[^\\d]", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); m = pattern.matcher(text); if (m.find()) { String speed = m.group(1); try { tracker.speed = Double.parseDouble(speed) / 3.6; } catch (NumberFormatException ignore) { } } pattern = Pattern.compile("imei[^\\d]{0,2}(\\d+)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); m = pattern.matcher(text); if (m.find()) { String imei = m.group(1); tracker.imei = imei; } pattern = Pattern.compile("bat(?:tery)?[^\\d]{0,2}(\\d{1,3})[^\\d]", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); m = pattern.matcher(text); if (m.find()) { String batter = m.group(1); try { tracker.battery = Integer.parseInt(batter); } catch (NumberFormatException ignore) { } } Log.w(TAG, "parseFlexMode OK " + tracker.latitude + ", " + tracker.longitude); return true; }
From source file:org.pentaho.osgi.platform.webjars.WebjarsURLConnectionTest.java
private void verifyBlueprint(ZipFile zipInputStream, String expectedPath) throws IOException { ZipEntry entry = zipInputStream.getEntry("OSGI-INF/blueprint/blueprint.xml"); assertNotNull(entry);//from w w w . j a v a2s .c om String bpFile = IOUtils.toString(zipInputStream.getInputStream(entry), "UTF-8"); Pattern distPattern = Pattern.compile("<bean id=\"resourceMappingDist\".*>.*" + "<property name=\"alias\" value=\"\\/" + expectedPath + "\"\\/>.*" + "<property name=\"path\" value=\"\\/META-INF\\/resources\\/dist-gen\"\\/>.*" + "<\\/bean>", Pattern.DOTALL); Matcher matcher = distPattern.matcher(bpFile); assertTrue("blueprint.xml does not include path for minified " + expectedPath, matcher.find()); distPattern = Pattern.compile("<bean id=\"resourceMappingSrc\".*>.*" + "<property name=\"alias\" value=\"\\/webjar-src\\/" + expectedPath + "\"\\/>.*" + "<property name=\"path\" value=\"\\/META-INF\\/resources\\/webjars\\/" + expectedPath + "\"\\/>.*" + "<\\/bean>", Pattern.DOTALL); matcher = distPattern.matcher(bpFile); assertTrue("blueprint.xml does not include path for " + expectedPath + " sources", matcher.find()); }
From source file:eu.nerdz.api.impl.fastreverse.messages.FastReverseConversationHandler.java
/** * Replaces a composite tag./*from ww w .java 2s.c om*/ * @param regex A regex * @param message A message to be parsed * @param format A format for pretty formatting. Only 2 string fields. * @return A string in which all occurrences of regex have been substituted with the contents matched */ private static String replaceDouble(String regex, String message, String format) { Matcher matcher = Pattern.compile(regex, Pattern.DOTALL | Pattern.CASE_INSENSITIVE).matcher(message); StringBuffer result = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(result, String.format(format, matcher.group(1), matcher.group(2)).replace("$", "\\$")); } matcher.appendTail(result); return result.toString(); }
From source file:biz.c24.io.spring.batch.reader.C24ItemReader.java
/** * In conjunction with the element start regex, used to detect the end of a message. Note that it is possible for a single * line to match both the start and stop patterns and hence be a complete element on its own. * //from ww w .j a va2 s. c o m * @param elementStopRegEx The regular expression to identify the end of an entity in the source */ public void setElementStopPattern(String elementStopRegEx) { this.elementStopPattern = Pattern.compile(elementStopRegEx, Pattern.DOTALL); }
From source file:com.gewara.util.XSSFilter.java
protected String checkTags(String s) { Pattern p = Pattern.compile("<(.*?)>", Pattern.DOTALL); Matcher m = p.matcher(s);// ww w .ja v a 2 s . c om StringBuffer buf = new StringBuffer(); while (m.find()) { String replaceStr = m.group(1); replaceStr = processTag(replaceStr); m.appendReplacement(buf, replaceStr); } m.appendTail(buf); s = buf.toString(); // these get tallied in processTag // (remember to reset before subsequent calls to filter method) for (String key : vTagCounts.keySet()) { for (int ii = 0; ii < vTagCounts.get(key); ii++) { s += "</" + key + ">"; } } return s; }
From source file:de.undercouch.bson4jackson.BsonParserTest.java
@Test public void parseComplex() throws Exception { BSONObject o = new BasicBSONObject(); o.put("Timestamp", new BSONTimestamp(0xAABB, 0xCCDD)); o.put("Symbol", new Symbol("Test")); o.put("ObjectId", new org.bson.types.ObjectId(Integer.MAX_VALUE, -2, Integer.MIN_VALUE)); Pattern p = Pattern.compile(".*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE | Pattern.UNICODE_CASE); o.put("Regex", p); Map<?, ?> data = parseBsonObject(o); assertEquals(new Timestamp(0xAABB, 0xCCDD), data.get("Timestamp")); assertEquals(new de.undercouch.bson4jackson.types.Symbol("Test"), data.get("Symbol")); ObjectId oid = (ObjectId) data.get("ObjectId"); assertEquals(Integer.MAX_VALUE, oid.getTime()); assertEquals(-2, oid.getMachine());/* w w w . j av a 2 s. c o m*/ assertEquals(Integer.MIN_VALUE, oid.getInc()); Pattern p2 = (Pattern) data.get("Regex"); assertEquals(p.flags(), p2.flags()); assertEquals(p.pattern(), p2.pattern()); }
From source file:net.pms.util.OpenSubtitle.java
public static String getMovieInfo(File f) throws IOException { String info = checkMovieHash(getHash(f)); if (StringUtils.isEmpty(info)) { return ""; }//from www .jav a 2 s . c om @SuppressWarnings("unused") Pattern re = Pattern.compile("MovieImdbID.*?<string>([^<]+)</string>", Pattern.DOTALL); LOGGER.debug("info is " + info); return info; }
From source file:com.gs.obevo.db.apps.reveng.AquaRevengMain.java
private ImmutableMap<ChangeType, Pattern> initPatternMap(Platform platform) { MutableMap<String, Pattern> params = Maps.mutable.<String, Pattern>with() .withKeyValue(ChangeType.SP_STR, Pattern.compile("(?i)create\\s+proc(?:edure)?\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.FUNCTION_STR, Pattern.compile("(?i)create\\s+func(?:tion)?\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.VIEW_STR, Pattern.compile("(?i)create\\s+view\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.SEQUENCE_STR, Pattern.compile("(?i)create\\s+seq(?:uence)?\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.TABLE_STR, Pattern.compile("(?i)create\\s+table\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.DEFAULT_STR, Pattern.compile("(?i)create\\s+default\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.RULE_STR, Pattern.compile("(?i)create\\s+rule\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.USERTYPE_STR, Pattern.compile("(?i)^\\s*sp_addtype\\s+", Pattern.DOTALL)) .withKeyValue(ChangeType.INDEX_STR, Pattern.compile( "(?i)create\\s+(?:unique\\s+)?(?:\\w+\\s+)?index\\s+\\w+\\s+on\\s+(\\w+)", Pattern.DOTALL)); MutableMap<ChangeType, Pattern> patternMap = Maps.mutable.<ChangeType, Pattern>with(); for (String changeTypeName : params.keysView()) { if (platform.hasChangeType(changeTypeName)) { ChangeType changeType = platform.getChangeType(changeTypeName); patternMap.put(changeType, params.get(changeTypeName)); }/* w w w .j a v a2 s . c o m*/ } return patternMap.toImmutable(); }
From source file:com.qmetry.qaf.automation.util.StringUtil.java
public static boolean seleniumEquals(String expectedPattern, String actual) { if ((expectedPattern == null) || (actual == null)) { return expectedPattern == actual; }// www .j a va 2s . c o m if (actual.startsWith("regexp:") || actual.startsWith("regex:") || actual.startsWith("regexpi:") || actual.startsWith("regexi:") || actual.startsWith("start:") || actual.startsWith("end:") || actual.startsWith("in:")) { // swap 'em String tmp = actual; actual = expectedPattern; expectedPattern = tmp; } if (expectedPattern.startsWith("start:")) { return actual.startsWith(expectedPattern.replaceFirst("start:", "")); } if (expectedPattern.startsWith("end:")) { return actual.endsWith(expectedPattern.replaceFirst("end:", "")); } if (expectedPattern.startsWith("in:")) { return actual.contains(expectedPattern.replaceFirst("in:", "")); } 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; }