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: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 {/*w ww. j av a 2s . com*/ 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.wso2.carbon.connector.integration.test.amazonsns.AmazonsnsConnectorIntegrationTest.java
/** * Load request from file.//from w w w . j a v a 2 s . c o m * * @param requestFileName the request file name * @return the string * @throws IOException Signals that an I/O exception has occurred. */ private String loadRequestFromFile(String requestFileName) throws IOException { String requestFilePath; String requestData; requestFilePath = requestFileName; requestData = getFileContent(requestFilePath); Properties prop = (Properties) connectorProperties.clone(); Matcher matcher = Pattern.compile("%s\\(([A-Za-z0-9]*)\\)", Pattern.DOTALL).matcher(requestData); while (matcher.find()) { String key = matcher.group(1); requestData = requestData.replaceAll("%s\\(" + key + "\\)", prop.getProperty(key)); } return requestData; }
From source file:lineage2.gameserver.Config.java
/** * Method abuseLoad.// ww w.j a va2 s. c o m */ public static void abuseLoad() { List<Pattern> tmp = new ArrayList<Pattern>(); LineNumberReader lnr = null; try { String line; lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(ANUSEWORDS_CONFIG_FILE), "UTF-8")); while ((line = lnr.readLine()) != null) { StringTokenizer st = new StringTokenizer(line, "\n\r"); if (st.hasMoreTokens()) { tmp.add(Pattern.compile(".*" + st.nextToken() + ".*", Pattern.DOTALL | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE)); } } ABUSEWORD_LIST = tmp.toArray(new Pattern[tmp.size()]); tmp.clear(); _log.info("Abuse: Loaded " + ABUSEWORD_LIST.length + " abuse words."); } catch (IOException e1) { _log.warn("Error reading abuse: " + e1); } finally { try { if (lnr != null) { lnr.close(); } } catch (Exception e2) { } } }
From source file:com.spotify.docker.client.DefaultDockerClientTest.java
@Test public void testLogsTimestamps() throws Exception { sut.pull(BUSYBOX_LATEST);/*w w w .j a v a 2 s .c o m*/ final String container = randomName(); final ContainerConfig volumeConfig = ContainerConfig.builder().image(BUSYBOX_LATEST) .cmd("echo", "This message should have a timestamp").build(); sut.createContainer(volumeConfig, container); sut.startContainer(container); sut.waitContainer(container); final ContainerInfo info = sut.inspectContainer(container); assertThat(info.state().running(), is(false)); assertThat(info.state().exitCode(), is(0)); final String logs; try (LogStream stream = sut.logs(info.id(), stdout(), stderr(), timestamps())) { logs = stream.readFully(); } final Pattern timestampPattern = Pattern.compile("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d+Z.*$", Pattern.DOTALL); assertTrue(timestampPattern.matcher(logs).matches()); assertThat(logs, containsString("This message should have a timestamp")); }
From source file:org.sakaiproject.tool.assessment.ui.listener.author.ItemAddListener.java
private String[] processFIBFINText(String entiretext) { String[] processedText = new String[2]; Pattern pattern1 = Pattern.compile("[\\{][^\\}]*[\\}]"); Matcher matcher1 = pattern1.matcher(entiretext); StringBuilder textStringBuilder1 = new StringBuilder(); String tmpString1 = null;//from www . j a v a 2s. c o m int index1 = 0; while (matcher1.find()) { String group = matcher1.group(); textStringBuilder1.append(entiretext.substring(index1, matcher1.start())); tmpString1 = group.replaceAll("<.*?>", ""); textStringBuilder1.append(tmpString1); index1 = matcher1.end(); } textStringBuilder1.append(entiretext.substring(index1)); String modifiedText = textStringBuilder1.toString(); //String[] tmpString = modifiedText.split("(<([a-z]\\w*)\\b[^>]*>(.*?)</\\1\\s*>)|(<([a-z]\\w*)\\b[^>]*/>)"); Pattern pattern2 = Pattern.compile("(<([a-z]\\w*)\\b[^>]*>(.*?)</\\1\\s*>)|(<([a-z]\\w*)\\b[^>]*/>)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher matcher2 = pattern2.matcher(modifiedText); int index2 = 0; StringBuilder textStringBuilder2 = new StringBuilder(); StringBuilder textStringBuilder3 = new StringBuilder(); String tmpString2 = null; while (matcher2.find()) { String group = matcher2.group(); log.debug("group" + group); tmpString2 = modifiedText.substring(index2, matcher2.start()); log.debug("tmpString2" + tmpString2); if (tmpString2 != null) { textStringBuilder2.append(tmpString2.replaceAll("[\\{][^\\}]*[\\}]", "{}")); textStringBuilder3.append(tmpString2); log.debug("textStringBuilder2=" + textStringBuilder2); log.debug("textStringBuilder3=" + textStringBuilder3); } textStringBuilder2.append(group); index2 = matcher2.end(); log.debug("index2=" + index2); } tmpString2 = modifiedText.substring(index2); if (tmpString2 != null) { textStringBuilder2.append(tmpString2.replaceAll("[\\{][^\\}]*[\\}]", "{}")); textStringBuilder3.append(tmpString2); log.debug("textStringBuilder2=" + textStringBuilder2); log.debug("textStringBuilder3=" + textStringBuilder3); } processedText[0] = textStringBuilder2.toString(); processedText[1] = textStringBuilder3.toString(); return processedText; }
From source file:org.wso2.carbon.connector.integration.test.eloqua.EloquaConnectorIntegrationTest.java
/** * Load a request from a file, provided by a filename. * * @param requestFileName The name of the file to load the request from. * @param parametersMap Map of parameters to replace within the parametrized values of the request. * @return String contents of the file./*from w w w .j a va 2 s. co m*/ * @throws IOException Thrown on inability to read from the file. */ private String loadRequestFromFile(String requestFileName, Map<String, String> parametersMap) throws IOException { String requestFilePath; String requestData; String pathToRequestsDirectory = repoLocation + connectorProperties.getProperty("requestDirectoryRelativePath"); requestFilePath = pathToRequestsDirectory + requestFileName; requestData = getFileContent(requestFilePath); Properties prop = (Properties) connectorProperties.clone(); if (parametersMap != null) { prop.putAll(parametersMap); } Matcher matcher = Pattern.compile("%s\\(([A-Za-z0-9]*)\\)", Pattern.DOTALL).matcher(requestData); while (matcher.find()) { String key = matcher.group(1); if (!key.equals("username") && !key.equals("password") && !key.equals("siteName")) { requestData = requestData.replaceAll("%s\\(" + key + "\\)", Matcher.quoteReplacement(prop.getProperty(key))); } if (key.equals("username") || key.equals("password") || key.equals("siteName")) { String str = "\"" + key + "\":\"%s\\(" + key + "\\)\",\n"; requestData = requestData.replaceAll(str, ""); } if (key.endsWith("Id")) { String prefix = requestData.trim().substring(requestData.indexOf("\"") + 1, requestData.indexOf(":") - 1); String str = "\"" + prefix + "\":\"%s\\(" + key + "\\)\",\n"; requestData = requestData.trim().replaceAll(str, ""); } } return requestData; }
From source file:com.rdm.common.util.StringUtils.java
/** * Replaces each substring of the source String that matches the given regular expression with the given * replacement using the {@link Pattern#DOTALL} option. DOTALL is also know as single-line mode in Perl. This call * is also equivalent to:/* w w w .j a v a2 s .co m*/ * <ul> * <li>{@code source.replaceAll("(?s)" + regex, replacement)}</li> * <li>{@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement)}</li> * </ul> * * @param source * the source string * @param regex * the regular expression to which this string is to be matched * @param replacement * the string to be substituted for each match * @return The resulting {@code String} * @see String#replaceAll(String, String) * @see Pattern#DOTALL * @since 3.2 */ public static String replacePattern(final String source, final String regex, final String replacement) { return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement); }
From source file:processing.core.PApplet.java
static Pattern matchPattern(String regexp) { Pattern p = null;/* ww w . ja v a 2 s .com*/ if (matchPatterns == null) { matchPatterns = new HashMap<String, Pattern>(); } else { p = matchPatterns.get(regexp); } if (p == null) { if (matchPatterns.size() == 10) { // Just clear out the match patterns here if more than 10 are // being // used. It's not terribly efficient, but changes that you have // >10 // different match patterns are very slim, unless you're doing // something really tricky (like custom match() methods), in // which // case match() won't be efficient anyway. (And you should just // be // using your own Java code.) The alternative is using a queue // here, // but that's a silly amount of work for negligible benefit. matchPatterns.clear(); } p = Pattern.compile(regexp, Pattern.MULTILINE | Pattern.DOTALL); matchPatterns.put(regexp, p); } return p; }
From source file:bfile.util.StringUtils.java
/** * <p>Replaces each substring of the source String that matches the given regular expression with the given * replacement using the {@link Pattern#DOTALL} option. DOTALL is also know as single-line mode in Perl.</p> * * This call is a {@code null} safe equivalent to: * <ul>/* w w w . j av a 2 s .co m*/ * <li>{@code source.replaceAll("(?s)" + regex, replacement)}</li> * <li>{@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement)}</li> * </ul> * * <p>A {@code null} reference passed to this method is a no-op.</p> * * <pre> * StringUtils.replacePattern(null, *, *) = null * StringUtils.replacePattern("any", null, *) = "any" * StringUtils.replacePattern("any", *, null) = "any" * StringUtils.replacePattern("", "", "zzz") = "zzz" * StringUtils.replacePattern("", ".*", "zzz") = "zzz" * StringUtils.replacePattern("", ".+", "zzz") = "" * StringUtils.replacePattern("<__>\n<__>", "<.*>", "z") = "z" * StringUtils.replacePattern("ABCabc123", "[a-z]", "_") = "ABC___123" * StringUtils.replacePattern("ABCabc123", "[^A-Z0-9]+", "_") = "ABC_123" * StringUtils.replacePattern("ABCabc123", "[^A-Z0-9]+", "") = "ABC123" * StringUtils.replacePattern("Lorem ipsum dolor sit", "( +)([a-z]+)", "_$2") = "Lorem_ipsum_dolor_sit" * </pre> * * @param source * the source string * @param regex * the regular expression to which this string is to be matched * @param replacement * the string to be substituted for each match * @return The resulting {@code String} * @see #replaceAll(String, String, String) * @see String#replaceAll(String, String) * @see Pattern#DOTALL * @since 3.2 * @since 3.5 Changed {@code null} reference passed to this method is a no-op. */ public static String replacePattern(final String source, final String regex, final String replacement) { if (source == null || regex == null || replacement == null) { return source; } return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement); }
From source file:com.processing.core.PApplet.java
static Pattern matchPattern(String regexp) { Pattern p = null;//from w ww.j a va2s .c o m if (matchPatterns == null) { matchPatterns = new HashMap<String, Pattern>(); } else { p = matchPatterns.get(regexp); } if (p == null) { if (matchPatterns.size() == 10) { // Just clear out the match patterns here if more than 10 are being // used. It's not terribly efficient, but changes that you have >10 // different match patterns are very slim, unless you're doing // something really tricky (like custom match() methods), in which // case match() won't be efficient anyway. (And you should just be // using your own Java code.) The alternative is using a queue here, // but that's a silly amount of work for negligible benefit. matchPatterns.clear(); } p = Pattern.compile(regexp, Pattern.MULTILINE | Pattern.DOTALL); matchPatterns.put(regexp, p); } return p; }