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.google.dart.tools.update.core.internal.UpdateUtils.java
private static List<Revision> parseRevisions(String urlString) throws IOException { String str = readUrlStream(urlString); Pattern linkPattern = Pattern.compile("<a[^>]+href=[\"']?([\"'>]+)[\"']?[^>]*>(.+?)</a>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher matcher = linkPattern.matcher(str); ArrayList<Revision> revisions = new ArrayList<Revision>(); while (matcher.find()) { if (matcher.group(0).contains("dart-editor-archive")) { String revision = matcher.group(2); //drop trailing slash revision = revision.replace("/", ""); //drop symbolic links (like "latest") if (isNumeric(revision)) { revisions.add(Revision.forValue(revision)); }/*from w w w. j av a2 s .c o m*/ } } return revisions; }
From source file:edu.harvard.i2b2.crc.dao.setfinder.querybuilder.temporal.TemporalSubQuery.java
private String addToRegExExpression(String sqlString, String regEx, String newSql) { StringBuilder sql = new StringBuilder(); Pattern p = Pattern.compile(regEx, Pattern.DOTALL | Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(sqlString); int lastIndex = 0; while (m.find()) { int endIndex = m.end(); String text = sqlString.substring(lastIndex, endIndex - getSqlDelimiter().length()); sql.append(text);/*from ww w . ja v a2 s .c o m*/ sql.append(newSql); sql.append(getSqlDelimiter()); lastIndex = endIndex; } sql.append(sqlString.substring(lastIndex)); return sql.toString(); }
From source file:com.enonic.vertical.adminweb.handlers.ContentNewsletterHandlerServlet.java
protected Map<String, Map<String, String>> parseOtherRecipients(ExtendedMap formItems) { Map<String, Map<String, String>> emailMap = new HashMap<String, Map<String, String>>(); if (formItems.containsKey(FORM_ITEM_KEY_OTHER_RECIPIENTS)) { String otherRecipients = formItems.getString(FORM_ITEM_KEY_OTHER_RECIPIENTS); Pattern p = Pattern.compile(RegexpUtil.REG_EXP_VALID_EMAIL, Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(otherRecipients); while (m.find()) { Map<String, String> paramMap = new HashMap<String, String>(); String email = m.group(0); paramMap.put("recipientName", email.substring(0, email.indexOf('@'))); paramMap.put("recipientEmail", email); emailMap.put(email, paramMap); }/*from w w w.j ava 2 s . co m*/ } return emailMap; }
From source file:net.kamhon.ieagle.dao.Jpa2Dao.java
/** * convert hibernate positional parameter to JPA positional parameter notation.</br> For example: convert * <code>select a from A a where a.id=? and a.status=?</code> to * <code>select a from A a where a.id=?1 and a.status=?2</code> * // ww w.j a v a 2s. co m * @param query * @return */ public String convertJpaPositionParams(String query) { if (StringUtils.isBlank(query)) return query; // bypass if the query is using JPA positional parameter notation if (query.indexOf("?1") >= 0) { return query; } else if (query.indexOf("?") >= 0) { StringBuffer sb = new StringBuffer(); Pattern p = Pattern.compile(Pattern.quote("?"), Pattern.CASE_INSENSITIVE); Matcher matcher = p.matcher(query); boolean result = matcher.find(); int count = 0; while (result) { String g = matcher.group(); matcher.appendReplacement(sb, g + (++count)); result = matcher.find(); } matcher.appendTail(sb); log.debug("sb.toString() = " + sb.toString()); return sb.toString(); } return query; }
From source file:databaseadapter.GenerateMojo.java
private boolean isToInclude(String table) { if (includes == null || includes.length == 0) return true; for (String regex : includes) { getLog().debug("... checking table '" + table + "' against regex '" + regex + "' in order to check if it is to be included..."); Matcher matcher = Pattern.compile(regex, Pattern.CASE_INSENSITIVE).matcher(table); if (matcher.matches()) return true; }//from www.j av a 2 s .c o m return false; }
From source file:eu.trentorise.opendata.josman.JosmanProject.java
/** * Writes an md stream as html to outputFile * * @param outputFile Must not exist. Eventual needed directories in the path * will be created// w w w.j av a 2s . c o m * @param relPath path relative to {@link #sourceRepoDir}, i.e. * img/mypic.jpg or docs/README.md * @param version The version the md page refers to. * @param relpaths a list of relative paths for the sidebar */ void copyMdAsHtml(InputStream sourceMdStream, String relPath, final SemVersion version, List<String> relpaths) { checkNotNull(version); checkNotEmpty(relPath, "Invalid relative path!"); checkNotEmpty(relpaths, "Invalid relative paths!"); final String prependedPath = Josmans.prependedPath(relPath); File targetFile = Josmans.targetFile(pagesDir, relPath, version); if (targetFile.exists()) { throw new RuntimeException("Trying to write md file to target that already exists!! Target is " + targetFile.getAbsolutePath()); } String sourceMdString; try { StringWriter writer = new StringWriter(); IOUtils.copy(sourceMdStream, writer, "UTF-8"); // todo fixed encoding... sourceMdString = writer.toString(); } catch (Exception ex) { throw new RuntimeException( "Couldn't read source md stream! Target path is " + targetFile.getAbsolutePath(), ex); } Josmans.checkNotMeaningful(sourceMdString, "Invalid source md file!"); String filteredSourceMdString = sourceMdString.replaceAll("#\\{version}", version.toString()) .replaceAll("#\\{majorMinorVersion}", Josmans.majorMinor(version)) .replaceAll("#\\{repoRelease}", Josmans.repoRelease(repoOrganization, repoName, version)) .replaceAll("jedoc", "josman"); // for legacy compat String skeletonString; try { StringWriter writer = new StringWriter(); InputStream stream = Josmans.findResourceStream("/skeleton.html"); IOUtils.copy(stream, writer, "UTF-8"); skeletonString = writer.toString(); } catch (Exception ex) { throw new RuntimeException("Couldn't read skeleton file!", ex); } String skeletonStringFixedPaths; if (Josmans.isRootpath(relPath)) { skeletonStringFixedPaths = skeletonString; } else { // fix paths skeletonStringFixedPaths = skeletonString.replaceAll("src=\"js/", "src=\"../js/") .replaceAll("src=\"img/", "src=\"../img/").replaceAll("href=\"css/", "href=\"../css/"); } Jerry skeleton = Jerry.jerry(skeletonStringFixedPaths); skeleton.$("title").text(repoTitle); String contentFromMdHtml = pegDownProcessor.markdownToHtml(filteredSourceMdString); Jerry contentFromMd = Jerry.jerry(contentFromMdHtml); contentFromMd.$("a").each(new JerryFunction() { @Override public boolean onNode(Jerry arg0, int arg1) { String href = arg0.attr("href"); if (href.startsWith(prependedPath + "src")) { arg0.attr("href", href.replace(prependedPath + "src", Josmans.repoRelease(repoOrganization, repoName, version) + "/src")); return true; } if (href.endsWith(".md")) { arg0.attr("href", Josmans.htmlizePath(href)); return true; } if (href.equals(prependedPath + "../../wiki")) { arg0.attr("href", href.replace(prependedPath + "../../wiki", Josmans.repoWiki(repoOrganization, repoName))); return true; } if (href.equals(prependedPath + "../../issues")) { arg0.attr("href", href.replace(prependedPath + "../../issues", Josmans.repoIssues(repoOrganization, repoName))); return true; } if (href.equals(prependedPath + "../../milestones")) { arg0.attr("href", href.replace(prependedPath + "../../milestones", Josmans.repoMilestones(repoOrganization, repoName))); return true; } if (TodUtils.removeTrailingSlash(href).equals(DOCS_FOLDER)) { arg0.attr("href", Josmans.majorMinor(version) + "/index.html"); return true; } if (href.startsWith(DOCS_FOLDER + "/")) { arg0.attr("href", Josmans.majorMinor(version) + href.substring(DOCS_FOLDER.length())); return true; } return true; } }); contentFromMd.$("img").each(new JerryFunction() { @Override public boolean onNode(Jerry arg0, int arg1) { String src = arg0.attr("src"); if (src.startsWith(DOCS_FOLDER + "/")) { arg0.attr("src", Josmans.majorMinor(version) + src.substring(DOCS_FOLDER.length())); return true; } return true; } }); skeleton.$("#josman-internal-content").html(contentFromMd.html()); skeleton.$("#josman-repo-link").html(repoTitle).attr("href", prependedPath + "index.html"); File programLogo = programLogo(sourceDocsDir(), repoName); if (programLogo.exists()) { skeleton.$("#josman-program-logo").attr("src", prependedPath + "img/" + repoName + "-logo-200px.png"); skeleton.$("#josman-program-logo-link").attr("href", prependedPath + "index.html"); } else { skeleton.$("#josman-program-logo-link").css("display", "none"); } skeleton.$("#josman-wiki").attr("href", Josmans.repoWiki(repoOrganization, repoName)); skeleton.$("#josman-project").attr("href", Josmans.repoUrl(repoOrganization, repoName)); skeleton.$("#josman-home").attr("href", prependedPath + "index.html"); if (Josmans.isRootpath(relPath)) { skeleton.$("#josman-home").addClass("josman-tag-selected"); } // cleaning example versions skeleton.$(".josman-version-tab-header").remove(); List<RepositoryTag> tags = new ArrayList( Josmans.versionTagsToProcess(repoName, repoTags, ignoredVersions).values()); Collections.reverse(tags); if (Josmans.isRootpath(relPath)) { skeleton.$("#josman-internal-sidebar").text(""); skeleton.$("#josman-sidebar-managed-block").css("display", "none"); } else { Jerry sidebar = makeSidebar(contentFromMdHtml, relPath, relpaths); skeleton.$("#josman-internal-sidebar").html(sidebar.htmlAll(true)); } skeleton.$(".josman-to-strip").remove(); if (snapshotMode) { if (tags.size() > 0) { SemVersion ver = Josmans.version(repoName, tags.get(0).getName()); if (version.getMajor() >= ver.getMajor() && version.getMinor() >= ver.getMinor()) { addVersionHeaderTag(skeleton, prependedPath, version, prependedPath.length() != 0); } } else { addVersionHeaderTag(skeleton, prependedPath, version, prependedPath.length() != 0); } } else { for (RepositoryTag tag : tags) { SemVersion ver = Josmans.version(repoName, tag.getName()); addVersionHeaderTag(skeleton, prependedPath, ver, !Josmans.isRootpath(relPath) && ver.equals(version)); } Pattern p = Pattern.compile("todo", Pattern.CASE_INSENSITIVE); Matcher matcher = p.matcher(skeleton.html()); if (matcher.find()) { //throw new RuntimeException("Found '" + matcher.group() + "' string in stream for " + targetFile.getAbsolutePath() + " (at position " + matcher.start() + ")"); LOG.warning("Found '" + matcher.group() + "' string in stream for " + targetFile.getAbsolutePath()); } } if (!targetFile.getParentFile().exists()) { if (!targetFile.getParentFile().mkdirs()) { throw new RuntimeException("Couldn't create target directories to host processed md file " + targetFile.getAbsolutePath()); } } try { FileUtils.write(targetFile, skeleton.html()); } catch (Exception ex) { throw new RuntimeException("Couldn't write into " + targetFile.getAbsolutePath() + "!", ex); } }
From source file:com.funtl.framework.smoke.core.commons.persistence.Page.java
/** * ??/* w w w.j a va 2s .c o m*/ * * @return */ @JsonIgnore public String getOrderBy() { // SQL String reg = "(?:')|(?:--)|(/\\*(?:.|[\\n\\r])*?\\*/)|" + "(\\b(select|update|and|or|delete|insert|trancate|char|into|substr|ascii|declare|exec|count|master|into|drop|execute)\\b)"; Pattern sqlPattern = Pattern.compile(reg, Pattern.CASE_INSENSITIVE); if (sqlPattern.matcher(orderBy).find()) { return ""; } return orderBy; }
From source file:de.javakaffee.kryoserializers.KryoTest.java
@Test(enabled = true) public void testRegex() throws Exception { final Holder<Pattern> pattern = new Holder<Pattern>(Pattern.compile("regex")); @SuppressWarnings("unchecked") final Holder<Pattern> deserialized = deserialize(serialize(pattern), Holder.class); assertDeepEquals(deserialized, pattern); final Holder<Pattern> patternWithFlags = new Holder<Pattern>( Pattern.compile("\n", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE)); @SuppressWarnings("unchecked") final Holder<Pattern> deserializedWithFlags = deserialize(serialize(patternWithFlags), Holder.class); assertDeepEquals(deserializedWithFlags, patternWithFlags); }
From source file:com.awrtechnologies.carbudgetsales.MainActivity.java
public boolean emailValidator(String email) { String regExpn = "^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]{1}|[\\w-]{2,}))@" + "((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?" + "[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\." + "([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?" + "[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|" + "([a-zA-Z]+[\\w-]+\\.)+[a-zA-Z]{2,4})$"; CharSequence inputStr = email; Pattern pattern = Pattern.compile(regExpn, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(inputStr); if (matcher.matches()) return true; else// w w w . jav a2 s . c o m return false; }
From source file:com.dragoniade.deviantart.deviation.SearchRss.java
public List<Collection> getCollections() { List<Collection> collections = new ArrayList<Collection>(); if (search.getCollection() == null) { collections.add(null);//from ww w. j a v a2 s .c o m return collections; } String queryString = "http://" + user + ".deviantart.com/" + search.getCollection() + "/"; GetMethod method = new GetMethod(queryString); try { int sc = -1; do { sc = client.executeMethod(method); if (sc != 200) { LoggableException ex = new LoggableException(method.getResponseBodyAsString()); Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), ex); int res = DialogHelper.showConfirmDialog(owner, "An error has occured when contacting deviantART : error " + sc + ". Try again?", "Continue?", JOptionPane.YES_NO_OPTION); if (res == JOptionPane.NO_OPTION) { return null; } } } while (sc != 200); InputStream is = method.getResponseBodyAsStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int read = -1; while ((read = is.read(buffer)) > -1) { baos.write(buffer, 0, read); if (baos.size() > 2097152) { int res = DialogHelper.showConfirmDialog(owner, "An error has occured: The document is too big (over 2 megabytes) and look suspicious. Abort?", "Continue?", JOptionPane.YES_NO_OPTION); if (res == JOptionPane.YES_NO_OPTION) { return null; } } } String charsetName = method.getResponseCharSet(); String body = baos.toString(charsetName); String regex = user + ".deviantart.com/" + search.getCollection() + "/([0-9]+)\"[^>]*>([^<]+)<"; Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(body); while (matcher.find()) { String id = matcher.group(1); String name = matcher.group(2); Collection c = new Collection(Long.parseLong(id), name); collections.add(c); } } catch (IOException e) { } finally { method.releaseConnection(); } collections.add(null); return collections; }