List of usage examples for java.util.regex Pattern CASE_INSENSITIVE
int CASE_INSENSITIVE
To view the source code for java.util.regex Pattern CASE_INSENSITIVE.
Click Source Link
From source file:com.lcw.one.common.persistence.BaseDao.java
/** * hqlorderBy?? /* www .jav a 2s . com*/ * @param qlString * @return */ private String removeOrders(String qlString) { Pattern p = Pattern.compile("order\\s*by[\\w|\\W|\\s|\\S]*", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(qlString); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, ""); } m.appendTail(sb); return sb.toString(); }
From source file:com.mhs.hboxmaintenanceserver.utils.Utils.java
/** * Get LIST of HBOX in DHCP//from w ww . jav a2 s. c o m * * @param ip_range * @param manufacturer * @return * @throws IOException */ public static Host[] getListOfHBox_IN_DHCP(String ip_range, String manufacturer) throws IOException { ProcessBuilder pb = new ProcessBuilder("nmap", "-sP", ip_range); Process process = pb.start(); ArrayList<Host> hosts; try (BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()))) { String line, hostname; Host host = null; Pattern pattern; Matcher matcher; hosts = new ArrayList<>(); while ((line = br.readLine()) != null) { if (host == null && line.contains("Nmap scan report for")) { pattern = Pattern.compile(IPADDRESS_PATTERN, Pattern.CASE_INSENSITIVE); matcher = pattern.matcher(line); host = new Host(); String ip_address = ""; while (matcher.find()) { ip_address += matcher.group(); } host.setIp_address(ip_address); } else if (host != null && line.matches("MAC Address: (.*) \\(" + manufacturer + "\\)")) { pattern = Pattern.compile(MACADDRESS_PATTERN, Pattern.CASE_INSENSITIVE); matcher = pattern.matcher(line); String mac_address = ""; while (matcher.find()) { mac_address += matcher.group(); } host.setMac_address(mac_address.replaceAll("\\:", "")); hostname = host.getMac_address(); hostname = hostname.substring(hostname.length() - 6, hostname.length()); host.setHost_name("HBOX-" + hostname.toLowerCase()); hosts.add(host); host = null; } } } if (!hosts.isEmpty()) { return hosts.toArray(new Host[hosts.size()]); } return null; }
From source file:com.symbian.driver.plugins.ftptelnet.FtpTransfer.java
public List<File> dir(File aSymbianPath) { LOGGER.info("Listing folder " + aSymbianPath.toString()); String lDir = aSymbianPath.getPath().replaceAll("\\\\", "/"); String lName = ".*"; if (lDir.contains("*")) { lDir = normalizePath(aSymbianPath.getParentFile()); lName = aSymbianPath.getName().replaceAll("\\*", "\\.\\*"); } else {//from w w w . j a va2s. c om if (!lDir.equals("/")) { lDir = normalizePath(aSymbianPath); } } Pattern lPattern = Pattern.compile(lName, Pattern.CASE_INSENSITIVE); List<File> lReturn = new LinkedList<File>(); if (connectFTP()) { try { if (iFTP.changeWorkingDirectory(lDir)) { FTPFile[] lFiles = iFTP.listFiles(); for (int i = 0; i < lFiles.length; i++) { if (lPattern.matcher(lFiles[i].getName()).matches()) { // convert file back to NT lReturn.add(new File(backToNT(new File(lDir, lFiles[i].getName()).getPath()))); } } } } catch (IOException lIOException) { LOGGER.log(Level.SEVERE, "FTP command failed : dir " + aSymbianPath, lIOException); } } return lReturn; }
From source file:edu.brown.workload.Workload.java
/** * /*from w w w. j a v a 2 s.c om*/ * @param input_path * @param catalog_db * @param limit * @throws Exception */ public Workload load(File input_path, Database catalog_db, Filter filter) throws Exception { if (debug.val) LOG.debug("Reading workload trace from file '" + input_path + "'"); this.input_path = input_path; long start = System.currentTimeMillis(); // HACK: Throw out traces unless they have the procedures that we're looking for Pattern temp_pattern = null; if (filter != null) { List<ProcedureNameFilter> procname_filters = filter.getFilters(ProcedureNameFilter.class); if (procname_filters.isEmpty() == false) { Set<String> names = new HashSet<String>(); for (ProcedureNameFilter f : procname_filters) { for (String name : f.getProcedureNames()) { names.add(Pattern.quote(name)); } // FOR } // FOR if (names.isEmpty() == false) { temp_pattern = Pattern.compile( String.format("\"NAME\":[\\s]*\"(%s)\"", StringUtil.join("|", names)), Pattern.CASE_INSENSITIVE); if (debug.val) { LOG.debug(String.format("Fast filter for %d procedure names", names.size())); LOG.debug("PATTERN: " + temp_pattern.pattern()); } } } } final Pattern pattern = temp_pattern; final AtomicInteger counters[] = new AtomicInteger[] { new AtomicInteger(0), // ELEMENT COUNTER new AtomicInteger(0), // TXN COUNTER new AtomicInteger(0), // QUERY COUNTER new AtomicInteger(0), // WEIGHTED TXN COUNTER new AtomicInteger(0), // WEIGHTED QUERY COUNTER }; List<Runnable> all_runnables = new ArrayList<Runnable>(); int num_threads = ThreadUtil.getMaxGlobalThreads(); // Create the reader thread first WorkloadUtil.ReadThread rt = new WorkloadUtil.ReadThread(this.input_path, pattern, num_threads); all_runnables.add(rt); // Then create all of our processing threads for (int i = 0; i < num_threads; i++) { WorkloadUtil.ProcessingThread lt = new WorkloadUtil.ProcessingThread(this, this.input_path, rt, catalog_db, filter, counters); rt.processingThreads.add(lt); all_runnables.add(lt); } // FOR if (debug.val) LOG.debug(String.format("Loading workload trace using %d ProcessThreads", rt.processingThreads.size())); ThreadUtil.runNewPool(all_runnables, all_runnables.size()); VerifyWorkload.verify(catalog_db, this); long stop = System.currentTimeMillis(); LOG.info(String.format("Loaded %d txns / %d queries from '%s' in %.1f seconds using %d threads", this.txn_traces.size(), counters[2].get(), this.input_path.getName(), (stop - start) / 1000d, num_threads)); if (counters[1].get() != counters[3].get() || counters[2].get() != counters[4].get()) { LOG.info( String.format("Weighted Workload: %d txns / %d queries", counters[3].get(), counters[4].get())); } return (this); }
From source file:com.xpn.xwiki.plugin.mailsender.MailSenderPlugin.java
/** * Creates a Multipart MIME Message (multiple content-types within the same message) from an existing mail * //from w ww . ja v a 2s .c om * @param mail The original Mail * @return The Multipart MIME message */ public Multipart createMimeMultipart(Mail mail, XWikiContext context) throws MessagingException, XWikiException, IOException { Multipart multipart; List<Attachment> rawAttachments = mail.getAttachments() != null ? mail.getAttachments() : new ArrayList<Attachment>(); if (mail.getHtmlPart() == null && mail.getAttachments() != null) { multipart = new MimeMultipart("mixed"); // Create the text part of the email BodyPart textPart = new MimeBodyPart(); textPart.setContent(mail.getTextPart(), "text/plain; charset=" + EMAIL_ENCODING); multipart.addBodyPart(textPart); // Add attachments to the main multipart for (Attachment attachment : rawAttachments) { multipart.addBodyPart(createAttachmentBodyPart(attachment, context)); } } else { multipart = new MimeMultipart("mixed"); List<Attachment> attachments = new ArrayList<Attachment>(); List<Attachment> embeddedImages = new ArrayList<Attachment>(); // Create the text part of the email BodyPart textPart; textPart = new MimeBodyPart(); textPart.setText(mail.getTextPart()); // Create the HTML part of the email, define the html as a multipart/related in case there are images Multipart htmlMultipart = new MimeMultipart("related"); BodyPart htmlPart = new MimeBodyPart(); htmlPart.setContent(mail.getHtmlPart(), "text/html; charset=" + EMAIL_ENCODING); htmlPart.setHeader("Content-Disposition", "inline"); htmlPart.setHeader("Content-Transfer-Encoding", "quoted-printable"); htmlMultipart.addBodyPart(htmlPart); // Find images used with src="cid:" in the email HTML part Pattern cidPattern = Pattern.compile("src=('|\")cid:([^'\"]*)('|\")", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); Matcher matcher = cidPattern.matcher(mail.getHtmlPart()); List<String> foundEmbeddedImages = new ArrayList<String>(); while (matcher.find()) { foundEmbeddedImages.add(matcher.group(2)); } // Loop over the attachments of the email, add images used from the HTML to the list of attachments to be // embedded with the HTML part, add the other attachements to the list of attachments to be attached to the // email. for (Attachment attachment : rawAttachments) { if (foundEmbeddedImages.contains(attachment.getFilename())) { embeddedImages.add(attachment); } else { attachments.add(attachment); } } // Add the images to the HTML multipart (they should be hidden from the mail reader attachment list) for (Attachment image : embeddedImages) { htmlMultipart.addBodyPart(createAttachmentBodyPart(image, context)); } // Wrap the HTML and text parts in an alternative body part and add it to the main multipart Multipart alternativePart = new MimeMultipart("alternative"); BodyPart alternativeMultipartWrapper = new MimeBodyPart(); BodyPart htmlMultipartWrapper = new MimeBodyPart(); alternativePart.addBodyPart(textPart); htmlMultipartWrapper.setContent(htmlMultipart); alternativePart.addBodyPart(htmlMultipartWrapper); alternativeMultipartWrapper.setContent(alternativePart); multipart.addBodyPart(alternativeMultipartWrapper); // Add attachments to the main multipart for (Attachment attachment : attachments) { multipart.addBodyPart(createAttachmentBodyPart(attachment, context)); } } return multipart; }
From source file:com.vladsch.idea.multimarkdown.editor.MultiMarkdownPreviewEditor.java
protected String makeHtmlPage(String html) { VirtualFile file = FileDocumentManager.getInstance().getFile(document); // scan for <table>, </table>, <tr>, </tr> and other tags we modify, this could be done with a custom plugin to pegdown but // then it would be more trouble to get un-modified HTML. String regex = "(<table>|<thead>|<tbody>|<tr>|<hr/>|<del>|</del>|</p>|<kbd>|</kbd>|<var>|</var>";//|<code>|</code>"; StringBuilder result = new StringBuilder(html.length() + (html.length() >> 2)); String gitHubHref = MultiMarkdownPathResolver.getGitHubDocumentURL(project, document, !isWikiDocument); String gitHubClose = ""; if (gitHubHref == null) { gitHubHref = ""; } else {/*from www .jav a 2 s. co m*/ gitHubHref = "<a href=\"" + gitHubHref + "\" name=\"wikipage\" id=\"wikipage\">"; gitHubClose = "</a>"; } if (isWikiDocument) { result.append("<body class=\"multimarkdown-wiki-preview\">\n<div class=\"content\">\n"); result.append("" + "<h1 class=\"first-child\">").append(gitHubHref) .append(escapeHtml(file == null ? "" : file.getNameWithoutExtension().replace('-', ' '))) .append(gitHubClose).append("</h1>\n").append(""); } else { result.append("<body class=\"multimarkdown-preview\">\n<div class=\"content\">\n" + "<div class=\"page-header\">").append(gitHubHref) .append(escapeHtml(file == null ? "" : file.getName().replace('-', ' '))).append(gitHubClose) .append("</div>\n").append("<div class=\"hr\"></div>\n").append(""); // for now nothing regex += "|<h1>"; } String regexTail = "|<li>\\n*\\s*<p>"; boolean isDarkTheme = isDarkTheme(); boolean taskLists = isTaskLists(); if (taskLists) { regex += "|<li class=\"task-list-item\">\\n*\\s*<p>|<br\\s*/?>|<li class=\"task-list-item\">|<li>\\[(?:x|X)\\]\\s*|<li>\\[ \\]\\s*|<li>\\n*\\s*<p>\\[x\\]\\s*|<li>\\n*\\s*<p>\\[ \\]\\s*"; } regex += regexTail; regex += ")"; Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(html); int lastPos = 0; int rowCount = 0; boolean[] isOrderedList = new boolean[20]; int listDepth = -1; boolean firstChildH1 = !isWikiDocument; while (m.find()) { String found = m.group(); if (lastPos < m.start(0)) { result.append(html.substring(lastPos, m.start(0))); } if (found.equals("</p>")) { result.append(found); } else if (found.startsWith("<br")) { result.append("<br/>\n"); } else if (found.equals("<table>")) { rowCount = 0; result.append(found); } else if (found.equals("<thead>")) { result.append(found); } else if (found.equals("<tbody>")) { result.append(found); } else if (found.equals("/>")) { result.append(">"); } else if (found.equals("<tr>")) { rowCount++; result.append("<tr class=\"") .append(rowCount == 1 ? "first-child" : (rowCount & 1) != 0 ? "odd-child" : "even-child") .append("\">"); } else if (found.equals("<hr/>")) { result.append("<div class=\"hr\"> </div>"); } else if (found.equals("<h1>")) { result.append(firstChildH1 ? "<h1 class=\"first-child\">" : "<h1>"); firstChildH1 = false; } else if (found.equals("<del>")) { result.append("<span class=\"del\">"); } else if (found.equals("</del>")) { result.append("</span>"); } else if (found.equals("<kbd>")) { result.append("<span class=\"kbd\">"); } else if (found.equals("</kbd>")) { result.append("</span>"); } else if (found.equals("<code>")) { result.append("<span class=\"code\">"); } else if (found.equals("</code>")) { result.append("</span>"); } else if (found.equals("<var>")) { result.append("<span class=\"var\">"); } else if (found.equals("</var>")) { result.append("</span>"); } else { found = found.trim(); if (taskLists && found.equals("<li>[x]")) { result.append("<li class=\"dtask\">"); } else if (taskLists && found.equals("<li>[X]")) { result.append("<li class=\"dtask\">"); } else if (taskLists && found.equals("<li>[ ]")) { result.append("<li class=\"dtask\">"); } else if (taskLists && found.equals("<li class=\"task-list-item\">")) { result.append("<li class=\"taski\">"); } else { // here we have <li>\n*\s*<p>, need to strip out \n*\s* so we can match them easier String foundWithP = found; foundWithP = foundWithP.replaceAll("<li>\\n*\\s*<p>", "<li><p>"); found = foundWithP.replaceAll("<li class=\"task-list-item\">\\n*\\s*<p>", "<li class=\"task\"><p>"); found = found.trim(); if (found.equals("<li><p>")) { result.append("<li class=\"p\"><p class=\"p\">"); } else if (taskLists && found.equals("<li><p>[x]")) { result.append("<li class=\"dtaskp\"><p class=\"p\">"); } else if (taskLists && found.equals("<li><p>[ ]")) { result.append("<li class=\"dtaskp\"><p class=\"p\">"); } else if (taskLists && found.equals("<li class=\"task-list-item\"><p>")) { result.append("<li class=\"taskp\"><p class=\"p\">"); } else { result.append(found); } } } lastPos = m.end(0); } if (lastPos < html.length()) { result.append(html.substring(lastPos)); } result.append("\n</div>\n</body>\n"); return result.toString(); }
From source file:de.wikilab.android.friendica01.Max.java
public static Matcher regeximatch(String pattern, String string) { return Pattern.compile(pattern, Pattern.CASE_INSENSITIVE).matcher(string); }
From source file:loggerplusplus.LogEntry.java
public void processResponse(IHttpRequestResponse requestResponse) { if (!isImported) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date responseDate = new Date(); this.responseTime = sdf.format(responseDate); try {/*from ww w .j a v a2 s .com*/ Date requestDate = sdf.parse(this.requestTime); this.requestResponseDelay = formatDelay(responseDate.getTime() - requestDate.getTime()); } catch (ParseException e) { } } //Finalise request,response by saving to temp file and clearing from memory. if (requestResponse instanceof IHttpRequestResponsePersisted) { this.requestResponse = requestResponse; } else { this.requestResponse = LoggerPlusPlus.getCallbacks().saveBuffersToTempFiles(requestResponse); } IResponseInfo tempAnalyzedResp = LoggerPlusPlus.getCallbacks().getHelpers() .analyzeResponse(requestResponse.getResponse()); String strFullResponse = new String(requestResponse.getResponse()); this.responseBodyOffset = tempAnalyzedResp.getBodyOffset(); this.responseLength = requestResponse.getResponse().length - responseBodyOffset; LogTable logTable = LoggerPlusPlus.getInstance().getLogTable(); List<String> lstFullResponseHeader = tempAnalyzedResp.getHeaders(); responseHeaders = StringUtils.join(lstFullResponseHeader, ", "); this.status = tempAnalyzedResp.getStatusCode(); if (logTable.getColumnModel().isColumnEnabled("MimeType")) // This is good to increase the speed when it is time consuming this.responseMimeType = tempAnalyzedResp.getStatedMimeType(); if (logTable.getColumnModel().isColumnEnabled("InferredType")) // This is good to increase the speed when it is time consuming this.responseInferredMimeType = tempAnalyzedResp.getInferredMimeType(); if (logTable.getColumnModel().isColumnEnabled("newCookies")) // This is good to increase the speed when it is time consuming for (ICookie cookieItem : tempAnalyzedResp.getCookies()) { this.newCookies += cookieItem.getName() + "=" + cookieItem.getValue() + "; "; } this.hasSetCookies = !newCookies.isEmpty(); if (logTable.getColumnModel().isColumnEnabled("responseContentType")) { // This is good to increase the speed when it is time consuming for (String item : lstFullResponseHeader) { item = item.toLowerCase(); if (item.startsWith("content-type: ")) { String[] temp = item.split("content-type:\\s", 2); if (temp.length > 0) this.responseContentType = temp[1]; } } } Pattern titlePattern = Pattern.compile("(?<=<title>)(.)+(?=</title>)"); Matcher titleMatcher = titlePattern.matcher(strFullResponse); if (titleMatcher.find()) { this.title = titleMatcher.group(1); } // RegEx processing for responses - should be available only when we have a RegEx rule! // There are 5 RegEx rule for requests for (int i = 0; i < 5; i++) { String regexVarName = "regex" + (i + 1) + "Resp"; if (logTable.getColumnModel().isColumnEnabled(regexVarName)) { // so this rule is enabled! // check to see if the RegEx is not empty LogTableColumn regexColumn = logTable.getColumnModel().getColumnByName(regexVarName); String regexString = regexColumn.getRegExData().getRegExString(); if (!regexString.isEmpty()) { // now we can process it safely! Pattern p = null; try { if (regexColumn.getRegExData().isRegExCaseSensitive()) p = Pattern.compile(regexString); else p = Pattern.compile(regexString, Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(strFullResponse); StringBuilder allMatches = new StringBuilder(); int counter = 1; while (m.find()) { if (counter == 2) { allMatches.insert(0, ""); allMatches.append(""); } if (counter > 1) { allMatches.append("" + m.group() + ""); } else { allMatches.append(m.group()); } counter++; } this.regexAllResp[i] = allMatches.toString(); } catch (Exception e) { LoggerPlusPlus.getCallbacks().printError("Error in regular expression: " + regexString); } } } } if (!logTable.getColumnModel().isColumnEnabled("response") && !logTable.getColumnModel().isColumnEnabled("request")) { this.requestResponse = null; } this.complete = true; }
From source file:me.StevenLawson.TotalFreedomMod.TFM_Util.java
public static Date parseDateOffset(String time) { Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE); Matcher m = timePattern.matcher(time); int years = 0; int months = 0; int weeks = 0; int days = 0; int hours = 0; int minutes = 0; int seconds = 0; boolean found = false; while (m.find()) { if (m.group() == null || m.group().isEmpty()) { continue; }//from w ww . ja v a2 s .c om for (int i = 0; i < m.groupCount(); i++) { if (m.group(i) != null && !m.group(i).isEmpty()) { found = true; break; } } if (found) { if (m.group(1) != null && !m.group(1).isEmpty()) { years = Integer.parseInt(m.group(1)); } if (m.group(2) != null && !m.group(2).isEmpty()) { months = Integer.parseInt(m.group(2)); } if (m.group(3) != null && !m.group(3).isEmpty()) { weeks = Integer.parseInt(m.group(3)); } if (m.group(4) != null && !m.group(4).isEmpty()) { days = Integer.parseInt(m.group(4)); } if (m.group(5) != null && !m.group(5).isEmpty()) { hours = Integer.parseInt(m.group(5)); } if (m.group(6) != null && !m.group(6).isEmpty()) { minutes = Integer.parseInt(m.group(6)); } if (m.group(7) != null && !m.group(7).isEmpty()) { seconds = Integer.parseInt(m.group(7)); } break; } } if (!found) { return null; } Calendar c = new GregorianCalendar(); if (years > 0) { c.add(Calendar.YEAR, years); } if (months > 0) { c.add(Calendar.MONTH, months); } if (weeks > 0) { c.add(Calendar.WEEK_OF_YEAR, weeks); } if (days > 0) { c.add(Calendar.DAY_OF_MONTH, days); } if (hours > 0) { c.add(Calendar.HOUR_OF_DAY, hours); } if (minutes > 0) { c.add(Calendar.MINUTE, minutes); } if (seconds > 0) { c.add(Calendar.SECOND, seconds); } return c.getTime(); }