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:com.ikanow.infinit.e.harvest.enrichment.custom.UnstructuredAnalysisHarvester.java
private static Pattern createRegex(String regEx, String flags) { int nflags = 0; if (null != flags) { for (int i = 0; i < flags.length(); ++i) { char c = flags.charAt(i); switch (c) { case 'm': nflags |= Pattern.MULTILINE; break; case 'i': nflags |= Pattern.CASE_INSENSITIVE; break; case 'd': nflags |= Pattern.DOTALL; break; case 'u': nflags |= Pattern.UNICODE_CASE; break; case 'n': nflags |= Pattern.UNIX_LINES; break; }/*from ww w . ja va 2 s . c o m*/ } } return Pattern.compile(regEx, nflags); }
From source file:org.openmrs.module.htmlformentry.WorkflowStateTagTest.java
@Test public void checkboxShouldAppearCheckedIfCurrentlyInSpecifiedState() throws Exception { transitionToState(START_STATE, FURTHER_PAST_DATE); transitionToState(MIDDLE_STATE, PAST_DATE); new RegressionTestHelper() { @Override/* w w w .j ava 2 s . c o m*/ public String getFormName() { return XML_CHECKBOX_FORM_NAME; } @Override public void testBlankFormHtml(String html) { Pattern p = Pattern.compile(".*checked=\"true\"/><label for=\".*\">MIDDLE STATE.*", Pattern.MULTILINE | Pattern.DOTALL); Assert.assertTrue("Checkbox should be checked: " + html, p.matcher(html).matches()); } }.run(); }
From source file:com.tao.realweb.util.StringUtil.java
/** * html //from w w w . j a va2 s .com * * @param htmlstr * @return */ public static String removeHtmlTag(String htmlstr) { Pattern pat = Pattern.compile("\\s*<.*?>\\s*", Pattern.DOTALL | Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); // \\s?[s|Sc|Cr|Ri|Ip|Pt|T] Matcher m = pat.matcher(htmlstr); String rs = m.replaceAll(""); rs = rs.replaceAll(" ", " "); rs = rs.replaceAll("<", "<"); rs = rs.replaceAll(">", ">"); return rs; }
From source file:eu.finwest.dao.MockDataBuilder.java
private List<Listing> getStartuplyListings(int fromId, int toId) { List<Listing> listings = new ArrayList<Listing>(); List<String> startuplyIds = getStartuplyIds(); log.info("Loading " + startuplyIds.size() + " Startuply listings"); try {/*from ww w .j a v a 2s . co m*/ Pattern namePattern = Pattern.compile("<h1 id=\"companyNameHeader\"[^>]*>([^<]*)", Pattern.MULTILINE); Pattern websitePattern = Pattern.compile("<a href=\"http://([^\"]*)\">\\1", Pattern.MULTILINE); Pattern addressPattern = Pattern.compile( "<table id=\"branchTable\".*<td class=\"SortedColumn\">[^<]*</td>\\s*<td[^>]*>([^<]*)", Pattern.MULTILINE | Pattern.DOTALL); Pattern logoPattern = Pattern.compile("<img\\s+src=\"([^\"]*)\"\\s+id=\"ctl00_Content_Logo\"", Pattern.MULTILINE); Pattern industriesPattern = Pattern.compile( "<div[^>]*>Industries</div>\\s*<div[^>]*>\\s*<a[^>]*>([^<]*)</a>\\s*", Pattern.MULTILINE); Pattern industries2Pattern = Pattern.compile("\\s*,\\s*<a[^>]*>([^<]*)</a>", Pattern.MULTILINE); Pattern missionPattern = Pattern.compile("<h1[^>]*>[^<]* Mission</h1>\\s*<div[^>]*>\\s*([^<]*)", Pattern.MULTILINE); Pattern mantraPattern = Pattern.compile("([^\\.]+)"); Pattern productsPattern = Pattern.compile("<h1[^>]*>[^<]* Products</h1>\\s*<div[^>]*>\\s*([^<]*)", Pattern.MULTILINE); Pattern teamPattern = Pattern.compile("<h1[^>]*>[^<]* Team</h1>\\s*<div[^>]*>\\s*([^<]*)", Pattern.MULTILINE); Pattern lifePattern = Pattern.compile("<h1[^>]*>Life [^<]</h1>\\s*<div[^>]*>\\s*([^<]*)", Pattern.MULTILINE); int counter = 0; for (String startuplyId : startuplyIds) { counter++; if (counter <= fromId || counter >= toId) { continue; } String startuplyPath = STARTUPLY_ROOT + "/Companies/" + startuplyId + ".aspx"; StartuplyCache startuplyCache = null; try { startuplyCache = getOfy().get(StartuplyCache.class, startuplyPath); } catch (NotFoundException e) { ; } if (startuplyCache == null) { try { URL url = new URL(startuplyPath); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("GET"); StringWriter stringWriter = new StringWriter(); IOUtils.copy(connection.getInputStream(), stringWriter, "UTF-8"); String startuplyPage = stringWriter.toString(); connection.disconnect(); if (!StringUtils.isEmpty(startuplyPage)) { startuplyPage = startuplyPage.replaceAll("<br />", ""); // messes up multiline desc if we don't do this startuplyCache = new StartuplyCache(startuplyPath, startuplyPage); getOfy().put(startuplyCache); } } catch (Exception e) { log.log(Level.WARNING, "Exception while importing Startuply startup: " + startuplyId, e); } } if (startuplyCache == null) { log.info("Could not load Startuply cache for id: " + startuplyId); } else if (StringUtils.isEmpty(startuplyCache.page)) { log.info("Unable to import, empty response for Startuply cache page for id: " + startuplyId); } else { try { //log.info(startuplyCache.page); String name = ""; Matcher nameMatcher = namePattern.matcher(startuplyCache.page); if (nameMatcher.find()) { name = nameMatcher.group(1); } String address = ""; Matcher addressMatcher = addressPattern.matcher(startuplyCache.page); if (addressMatcher.find()) { address = addressMatcher.group(1); } String website = ""; Matcher websiteMatcher = websitePattern.matcher(startuplyCache.page); if (websiteMatcher.find()) { website = "http://" + websiteMatcher.group(1); } String logo = ""; Matcher logoMatcher = logoPattern.matcher(startuplyCache.page); if (logoMatcher.find()) { logo = STARTUPLY_ROOT + logoMatcher.group(1); } String industries = ""; Matcher industriesMatcher = industriesPattern.matcher(startuplyCache.page); if (industriesMatcher.find()) { industries = industriesMatcher.group(1); industriesMatcher.usePattern(industries2Pattern); while (industriesMatcher.find()) { industries += " " + industriesMatcher.group(1); } } String description = ""; String mantra = ""; Matcher missionMatcher = missionPattern.matcher(startuplyCache.page); if (missionMatcher.find()) { description = missionMatcher.group(1); Matcher mantraMatcher = mantraPattern.matcher(description); if (mantraMatcher.find()) { mantra = mantraMatcher.group(1); } } Matcher productsMatcher = productsPattern.matcher(startuplyCache.page); if (productsMatcher.find()) { String products = productsMatcher.group(1); description += " " + products; } Matcher teamMatcher = teamPattern.matcher(startuplyCache.page); if (teamMatcher.find()) { String team = teamMatcher.group(1); description += " " + team; } Matcher lifeMatcher = lifePattern.matcher(startuplyCache.page); if (lifeMatcher.find()) { String life = lifeMatcher.group(1); description += " " + life; } if (StringUtils.isEmpty(name)) { log.info("Unable to import, couldn't find name for Startuply id: " + startuplyId); } else { String type = bestGuessListingType(name, industries, description); //log.info("Matched name:[" + name + "] address:["+address + "] website:["+website + "] logo:["+logo + "] industries:["+industries+"] mantra:["+mantra+"] description:["+description+"]"); int askamt = 5 * new Random().nextInt(20) * 1000; int askpct = 5 + 5 * new Random().nextInt(9); if (askamt < 10000) { askamt = 0; } if (StringUtils.isEmpty(mantra)) { mantra = industries; } if (StringUtils.isEmpty(description)) { description = "In summary, " + name + " is a great company in the " + industries + " space."; } Listing listing = prepareListing(EN, STARTUPLY, // DtoToVoConverter.convert(user), name, Listing.State.ACTIVE, type, askamt, askpct, mantra, description, website, null, null, logo, address, false, false); listings.add(listing); //log.info("Added Startuply listing: "+listing); log.info("Added Startuply listing " + counter + " of " + startuplyIds.size() + " name: " + name); } } catch (Exception e) { log.log(Level.WARNING, "Exception while importing Startuply startup: " + startuplyId, e); } } } } catch (Exception e) { e.printStackTrace(); } return listings; }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java
public Date setSimpleDateFormat(String ParseDate) { Date dueDate = null; // set to null SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yy"); String beginStr1 = null;//from w w w . j a va2s . co m String endStr1 = null; String lookupPattern = "^(.*?)[0-9][0-9]-[0-9][0-9]-[0-9][0-9](.*?)$"; Pattern findPattern = Pattern.compile(lookupPattern, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); Matcher findPatternMatch = findPattern.matcher(ParseDate); while (findPatternMatch.find()) { beginStr1 = findPatternMatch.group(1).trim(); endStr1 = findPatternMatch.group(2).trim(); //LOG.debug("beginStr1: " + beginStr1 + ", endStr1: " + endStr1); } String strDate = ParseDate.replaceAll(beginStr1, "").replace(endStr1, "").replace("-", "/").trim(); // format string //LOG.debug("setSimpleDateFormat - Status Date: " + strDate); try { dueDate = dateFormat.parse(strDate); //LOG.debug("......DueDate: " + dueDate); } catch (ParseException pe) { LOG.debug("setSimpleDateFormat ERROR: Cannot parse \"" + strDate + "\""); } return dueDate; }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java
public StatusString setRenewSimpleDateFormat(String ParseDate) { Status iStatus = new Status(); StatusString RenewItemDateString = new StatusString(); //ParseDate = "DUE 05-19-12 <font color=\"(.*?)\"> TOO SOON TO RENEW</font> <span class=\"patFuncRenewCount\">Renewed 1 (time.*)</span>$"; //String patternValue = "^DUE(.*?)<font color=\"(.*?)\">(.*?)</font>(.*?)<span(.*?)class=\"patFuncRenewCount\">Renewed 1 (time.*)</span>$"; //ParseDate = "DUE 03-27-12 <b> RENEWED</b>Now due 05-19-12 <span class=\"patFuncRenewCount\">Renewed 2 times</span>"; String patternValue = "^DUE(.*?)<b>(.*?)</b>Now due(.*?)<span(.*?)class=\"patFuncRenewCount\">Renewed(.*?)(time.*)</span>$"; Pattern findPattern = Pattern.compile(patternValue, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); Matcher findPatternMatch = findPattern.matcher(ParseDate); if (findPatternMatch.find()) { iStatus.returnStatus = true;/* ww w. ja va 2s . c o m*/ iStatus.returnMsg = "MillenniumRemoteServiceManager-setRenewSimpleDateFormat - Success"; RenewItemDateString.recordStatus = iStatus; RenewItemDateString.statusValue = findPatternMatch.group(3); } else { patternValue = "^DUE(.*?)<font color=\"(.*?)\">(.*?)</font>(.*?)<span(.*?)class=\"patFuncRenewCount\">Renewed(.*?)(time.*)</span>$"; findPattern = Pattern.compile(patternValue, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); findPatternMatch = findPattern.matcher(ParseDate); if (findPatternMatch.find()) { iStatus.returnStatus = false; iStatus.returnMsg = "MillenniumRemoteServiceManager-setRenewSimpleDateFormat - False"; RenewItemDateString.recordStatus = iStatus; RenewItemDateString.statusValue = findPatternMatch.group(3); } else { iStatus.returnStatus = false; iStatus.returnMsg = "MillenniumRemoteServiceManager-setRenewSimpleDateFormat - Couldn't find pattern"; RenewItemDateString.recordStatus = iStatus; RenewItemDateString.statusValue = "MillenniumRemoteServiceManager-setRenewSimpleDateFormat - Couldn't find pattern"; } } return RenewItemDateString; }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java
public String getReminderLevel(String strStatus) { String reminderLevel = null;/* w ww. j av a 2 s . co m*/ //String beginStr1 = null; String endStr1 = null; String beginStr2 = null; String lookupPattern = "^(.*?)[0-9][0-9]-[0-9][0-9]-[0-9][0-9](.*?)$"; Pattern findPattern = Pattern.compile(lookupPattern, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); Matcher findPatternMatch = findPattern.matcher(strStatus); while (findPatternMatch.find()) { //beginStr1 = findPatternMatch.group(1).trim(); endStr1 = findPatternMatch.group(2).trim(); //LOG.debug("Millennium - beginStr1: " + beginStr1 + ", endStr1: '" + endStr1 + "'"); } if (endStr1.length() > 0 && endStr1.contains("RECALLED")) { lookupPattern = "^+(.*?)RECALLED(.*?)$"; findPattern = Pattern.compile(lookupPattern, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); findPatternMatch = findPattern.matcher(endStr1); while (findPatternMatch.find()) { beginStr2 = findPatternMatch.group(1).trim(); //LOG.debug("Millennium - beginStr2/beginStr1: " + beginStr2); } endStr1 = null; reminderLevel = beginStr2.replace("+", "").trim(); //LOG.debug("Millennium - ReminderLevel: " + reminderLevel); } LOG.debug("Reminderlevel: '" + reminderLevel + "'"); return reminderLevel; }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java
public String getItemFineAmount(String strStatus) { String itemFineAmount = null; //LOG.debug("strStatus: " + strStatus); String lookupPattern = "^(.*?)FINE(.*?)up to now(.*?)</font>(.*?)$"; Pattern findPattern = Pattern.compile(lookupPattern, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); Matcher findPatternMatch = findPattern.matcher(strStatus); while (findPatternMatch.find()) { itemFineAmount = findPatternMatch.group(3).replace(")", "").replace(".", "").replace("$", "").trim(); }/* www .j a va2 s . c om*/ LOG.debug("itemFineAmount: '" + itemFineAmount + "'"); return itemFineAmount; }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java
public String getpatFuncStatus(String strStatus) { String patFuncStatus = null;/*from ww w .ja v a 2s. co m*/ String beginStr1 = null; //String endStr1 = null; if (strStatus.contains("reqFillTimeMsg")) { String lookupPattern = "^(.*?)<span class=\"reqFillTimeMsg\">(.*?)</span>$"; Pattern findPattern = Pattern.compile(lookupPattern, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); Matcher findPatternMatch = findPattern.matcher(strStatus); while (findPatternMatch.find()) { beginStr1 = findPatternMatch.group(1).trim(); //endStr1 = findPatternMatch.group(2).trim(); //LOG.debug("beginStr1: " + beginStr1 + ", endStr1: '" + endStr1 + "'"); } patFuncStatus = beginStr1; } else { patFuncStatus = strStatus; } return patFuncStatus; }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java
public String getHoldQueuePosition(String strStatus) { String HoldQueuePosition = null; String beginStr1 = null;/*www.ja va2 s .c o m*/ //String endStr1 = null; String lookupPattern = "^(.*?)of(.*?)holds$"; Pattern findPattern = Pattern.compile(lookupPattern, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); Matcher findPatternMatch = findPattern.matcher(strStatus); //LOG.debug("strStatus in getHoldsQueuePosition: " + strStatus); while (findPatternMatch.find()) { beginStr1 = findPatternMatch.group(1).trim(); //endStr1 = findPatternMatch.group(2).trim(); //LOG.debug("beginStr1: " + beginStr1 + ", endStr1: '" + endStr1 + "'"); } HoldQueuePosition = beginStr1; return HoldQueuePosition; }