List of usage examples for java.util.regex Pattern MULTILINE
int MULTILINE
To view the source code for java.util.regex Pattern MULTILINE.
Click Source Link
From source file:org.codeexample.anchorlinks.CVAnchorContentIndexingFilter.java
public String getContentBetweenAnchorInWiki(StringBuilder remaining, String anchor1, String anchor2) throws IOException { // http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html // "<a name='Creating_Schedule_Policies'>Creating Schedule Policies</a>XXXX<a name='Auxiliary_Copy_Schedule_Policy'>Creating Schedule Policies</a>";// // doc.toString(); // long start = new Date().getTime(); // <span class="mw-headline" id="JDK_contents">JDK contents</span><a // href="/wiki/AppletViewer" title="AppletViewer">appletviewer</a><span // class="mw-headline" id="Ambiguity_between_a_JDK_and_an_SDK">Ambiguity // between a JDK and an SDK</span> // <span[^>]*id\s*=\s*(?:"|')?JDK_contents(?:'|")?[^>]*>[^<]*</span>(.*)<span[^>]*?id\s*=\s*(?:"|')?Ambiguity_between_a_JDK_and_an_SDK(?:'|")?[^>]*>[^<]*</span> Matcher matcher = Pattern .compile(getRegexToExtractContent(anchor1, anchor2), Pattern.DOTALL | Pattern.MULTILINE) .matcher(remaining);//from w ww. ja va 2s . co m String matchedText = ""; if (matcher.find()) { // System.out.println("found match"); String anchorText = Jsoup.parse(matcher.group(1)).text(); matchedText = anchorText + " " + Jsoup.parse(matcher.group(2)).text(); // System.out.println(matchedText); // int cnt = matcher.groupCount(); // if (cnt == 2) { String newRemaining = matcher.group(3); remaining.setLength(0); remaining.append(newRemaining); // } } // long end = new Date().getTime(); // System.out.println("Took: " + (end - start)); return matchedText; }
From source file:org.xwiki.contrib.mailarchive.utils.internal.MailUtils.java
@Override public DecodedMailContent decodeMailContent(final String originalHtml, final String originalBody, final boolean cut) throws IOException { String html = ""; String body = ""; if (!StringUtils.isEmpty(originalHtml)) { html = textUtils.unzipString(originalHtml); } else {/*from www . j a v a2 s. c o m*/ // body is only plain text if (!StringUtils.isBlank(originalBody)) { if (originalBody.startsWith("<html") || originalBody.startsWith("<meta") || originalBody.contains("<br>") || originalBody.contains("<br/>")) { html = originalBody; } } } if (!StringUtils.isBlank(html)) { Matcher m = Pattern.compile("<span [^>]*>From:<\\\\/span>", Pattern.MULTILINE).matcher(html); if (cut && m.find()) { html = html.substring(0, m.start() - 1); } else if (cut && html.contains("<b>From:</b>")) { html = html.substring(0, html.indexOf("<b>From:</b>") - 1); } return new DecodedMailContent(true, html); } else { body = originalBody; Matcher m = Pattern.compile("\\n[\\s]*From:", Pattern.MULTILINE).matcher(body); if (cut && m.find()) { body = body.substring(0, m.start() + 1); } return new DecodedMailContent(false, body); } }
From source file:opennlp.tools.textsimilarity.TextProcessor.java
/** * Splits input text into sentences./*from ww w. j a va2 s. c o m*/ * * @param txt * Input text * @return List of sentences */ public static ArrayList<String> splitToSentences(String text) { ArrayList<String> sentences = new ArrayList<String>(); if (text.trim().length() > 0) { String s = "[\\?!\\.]\"?[\\s+][A-Z0-9i]"; text += " XOXOX."; Pattern p = Pattern.compile(s, Pattern.MULTILINE); Matcher m = p.matcher(text); int idx = 0; String cand = ""; // while(m.find()){ // System.out.println(m.group()); // } while (m.find()) { cand += " " + text.substring(idx, m.end() - 1).trim(); boolean hasAbbrev = false; for (int i = 0; i < abbrevs.length; i++) { if (cand.toLowerCase().endsWith(abbrevs[i])) { hasAbbrev = true; break; } } if (!hasAbbrev) { sentences.add(cand.trim()); cand = ""; } idx = m.end() - 1; } if (idx < text.length()) { sentences.add(text.substring(idx).trim()); } if (sentences.size() > 0) { sentences.set(sentences.size() - 1, sentences.get(sentences.size() - 1).replace(" XOXOX.", "")); } } return sentences; }
From source file:cz.vity.freerapid.plugins.services.rapidshare_premium.RapidShareRunner.java
private void checkProblems() throws ServiceConnectionProblemException, YouHaveToWaitException { Matcher matcher;//from w w w. j ava 2s . co m final String contentAsString = client.getContentAsString(); matcher = Pattern.compile("IP address (.*?) is already", Pattern.MULTILINE).matcher(contentAsString); if (matcher.find()) { final String ip = matcher.group(1); throw new ServiceConnectionProblemException(String.format( "<b>RapidShare error:</b><br>Your IP address %s is already downloading a file. <br>Please wait until the download is completed.", ip)); } if (contentAsString.contains("Currently a lot of users")) { matcher = Pattern .compile("Please try again in ([0-9]+) minute", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE) .matcher(contentAsString); if (matcher.find()) { throw new YouHaveToWaitException("Currently a lot of users are downloading files.", Integer.parseInt(matcher.group(1)) * 60 + 20); } throw new ServiceConnectionProblemException( String.format("<b>RapidShare error:</b><br>Currently a lot of users are downloading files.")); } if (getContentAsString().contains("momentarily not available") || getContentAsString().contains("Server under repair")) { throw new ServiceConnectionProblemException("The server is momentarily not available."); } }
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());//from w w w. j a v a 2 s . co 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:com.andrada.sitracker.reader.SamlibAuthorPageReader.java
private Date getAuthorUpdateDate() throws AddAuthorException { Pattern pattern = Pattern.compile(Constants.AUTHOR_UPDATE_DATE_REGEX, Pattern.MULTILINE); Matcher matcher = pattern.matcher(pageContent); Date date = new Date(); if (matcher.find()) { SimpleDateFormat ft = new SimpleDateFormat(Constants.AUTHOR_UPDATE_DATE_FORMAT); try {// w w w. j a v a 2 s.c o m date = ft.parse(matcher.group(1)); } catch (ParseException e) { throw new AddAuthorException(AddAuthorException.AuthorAddErrors.AUTHOR_DATE_NOT_FOUND); } } return date; }
From source file:functionaltests.job.log.TestJobServerLogs.java
public static boolean matchLine(String text, String regex) { Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); return pattern.matcher(text).find(); }
From source file:com.android.tradefed.targetprep.FastbootDeviceFlasher.java
/** * Checks with the bootloader if the specified partition exists or not * * @param device the {@link ITestDevice} to operate on * @param partition the name of the partition to be checked *///from www.ja v a 2s . com protected boolean hasPartition(ITestDevice device, String partition) throws DeviceNotAvailableException { String partitionType = String.format("partition-type:%s", partition); CommandResult result = device.executeFastbootCommand("getvar", partitionType); if (!CommandStatus.SUCCESS.equals(result.getStatus()) || result.getStderr().contains("FAILED")) { return false; } Pattern regex = Pattern.compile(String.format("^%s:\\s*\\S+$", partitionType), Pattern.MULTILINE); return regex.matcher(result.getStderr()).find(); }
From source file:com.jsystem.j2autoit.AutoItAgent.java
public Map<String, Comparable<?>> executeAutoitFile(String fullPath, String workDir, String autoItLocation, int timeout, Vector<Object> params) { Exception threwOne = null;//from ww w .java 2s . com Hashtable<String, Comparable<?>> result = new Hashtable<String, Comparable<?>>(); File sfile = new File(fullPath); if (!sfile.exists()) { System.out.println(agentWorkDir.getAbsolutePath()); System.out.println("Couldn't find " + sfile); return result; } Command cmd = new Command(); cmd.setTimeout(timeout); String[] commandParams = new String[3 + params.size()]; commandParams[0] = getAutoExecuterItLocation(autoItLocation); ; commandParams[1] = "/ErrorStdOut"; commandParams[2] = sfile.getAbsolutePath(); Log.info("Parameters:\n"); for (int index = 0; index < params.size(); index++) { Log.info(params.get(index).toString() + NEW_LINE); commandParams[index + 3] = params.get(index).toString(); } cmd.setCmd(commandParams); File workingDirectory = new File(workDir); cmd.setDir(workingDirectory.exists() ? workingDirectory : agentWorkDir); try { Execute.execute(cmd, true); } catch (Exception e) { threwOne = e; } Log.info(" \n"); Log.info(" \n"); String scriptText = ""; try { scriptText = FileUtils.read(sfile); Pattern pattern = Pattern.compile("^Local \\$var = ([\\w\\d\\p{Punct} ]+)$", Pattern.MULTILINE); Matcher matcher = pattern.matcher(scriptText); if (matcher.find()) { Log.info("AutoIt Command : " + matcher.group(matcher.groupCount()) + NEW_LINE); } } catch (IOException ioException) { Log.throwable(ioException.getMessage(), ioException); } String stdoutText = cmd.getStdout().toString(); int returnCodeValue = cmd.getReturnCode(); String stderrText = cmd.getStderr().toString(); if (isUseScreenShot || threwOne != null || !stderrText.isEmpty()) { String windowName = UUID.randomUUID().toString(); new ScreenShotThread(windowName).start(); Log.infoLog("A screenshot with the uuid : " + windowName + NEW_LINE); } Log.messageLog(SCRIPT + ":\n" + scriptText + NEW_LINE); Log.messageLog(STDOUT + ":\n" + stdoutText + NEW_LINE); Log.messageLog(RETURN + ":\n" + returnCodeValue + NEW_LINE); Log.messageLog(STDERR + ":\n" + stderrText + NEW_LINE); result.put(SCRIPT, scriptText); result.put(STDOUT, stdoutText); result.put(RETURN, returnCodeValue); result.put(STDERR, stderrText); if (isDebug) { if (isAutoDeleteFiles) { HistoryFile.addFile(sfile); Log.infoLog("Adding " + sfile.getAbsolutePath() + " to \"For deletion files list\"\n"); } } else { sfile.deleteOnExit(); } return result; }
From source file:org.unitime.timetable.onlinesectioning.custom.purdue.DegreeWorksPlanScraper.java
public String getDegreePlans(OnlineSectioningServer server, XStudent student) throws SectioningException { ClientResource resource = null;//from w ww . j a v a 2 s.c om try { resource = new ClientResource(getDegreeWorksApiSite()); resource.setNext(iClient); // resource.addQueryParameter("terms", getBannerTerm(server.getAcademicSession())); resource.addQueryParameter("studentId", getBannerId(student)); String effectiveOnly = getDegreeWorksApiEffectiveOnly(); if (effectiveOnly != null) resource.addQueryParameter("effectiveOnly", effectiveOnly); resource.setChallengeResponse(ChallengeScheme.HTTP_BASIC, getDegreeWorksApiUser(), getDegreeWorksApiPassword()); try { resource.get(MediaType.APPLICATION_JSON); } catch (ResourceException exception) { try { String response = IOUtils.toString(resource.getResponseEntity().getReader()); Pattern pattern = Pattern.compile(getDegreeWorksErrorPattern(), Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.UNIX_LINES); Matcher match = pattern.matcher(response); if (match.find()) throw new SectioningException(match.group(1)); } catch (SectioningException e) { throw e; } catch (Throwable t) { throw exception; } throw exception; } return IOUtils.toString(resource.getResponseEntity().getReader()); } catch (SectioningException e) { throw e; } catch (Exception e) { throw new SectioningException(e.getMessage()); } finally { if (resource != null) { if (resource.getResponse() != null) resource.getResponse().release(); resource.release(); } } }