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.intuit.tank.tools.debugger.FindReplaceDialog.java
private void find(RSyntaxTextArea textArea) { try {//from w w w . j a va 2s . co m int offset = currentLine < textArea.getLineCount() ? textArea.getLineStartOffset(currentLine) : 0; String searchTerm = tfSearchEditor.getText(); String text = textArea.getText(); int foundIndex = -1; int flags = (checkboxRegexp.isSelected() ? 0 : Pattern.LITERAL) | (checkboxMatchCase.isSelected() ? 0 : Pattern.CASE_INSENSITIVE); Pattern p = Pattern.compile(searchTerm, flags); Matcher matcher = p.matcher(text); matcher.region(offset, text.length()); if (matcher.find()) { foundIndex = matcher.start(); } else if (checkboxWrap.isSelected() && offset > 0) { matcher.region(0, offset); if (matcher.find()) { foundIndex = matcher.start(); } } if (foundIndex != -1) { int lineOfOffset = textArea.getLineOfOffset(foundIndex); // textArea.setActiveLineRange(lineOfOffset, lineOfOffset); textArea.setCurrentLine(lineOfOffset); // textArea.setCaretPosition(foundIndex + searchTerm.length()); parent.repaint(); parent.fireStepChanged(lineOfOffset); currentLine = lineOfOffset + 1; } else { JOptionPane.showMessageDialog(parent, "Search String not found."); } } catch (Exception e) { e.printStackTrace(); } }
From source file:de.appsolve.padelcampus.admin.controller.general.AdminGeneralModulesController.java
private void rewriteLinks(Module model) { if (model.getId() != null) { Module existingModule = moduleDAO.findById(model.getId()); if (!model.getUrlTitle().equals(existingModule.getUrlTitle())) { String oldHref = String.format("href=\"(%s|/page%s)\"", existingModule.getUrl(), existingModule.getUrl()); String newHref = String.format("href=\"%s\"", model.getUrl()); Pattern p = Pattern.compile(oldHref, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); for (PageEntry pageEntry : pageEntryDAO.findAll()) { String message = pageEntry.getMessage(); if (!StringUtils.isEmpty(message)) { Matcher m = p.matcher(message); if (m.find()) { LOG.info(String.format("replacing links %s by %s in page entry %s", oldHref, newHref, pageEntry.getId())); pageEntry.setMessage(m.replaceAll(newHref)); pageEntryDAO.saveOrUpdate(pageEntry); }//w w w . j av a 2 s .com } } } } }
From source file:de.mpg.escidoc.services.syndication.feed.Feed.java
/** * Populate parameters with the values taken from the certain <code>uri</code> * and populate <code>paramHash</code> with the parameter/value paars. * @param uri// w ww .java 2 s. c o m * @throws SyndicationException */ private void populateParamsFromUri(String uri) throws SyndicationException { Utils.checkName(uri, "Uri is empty"); String um = getUriMatcher(); Utils.checkName(um, "Uri matcher is empty"); Matcher m = Pattern.compile(um, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(uri); if (m.find()) { for (int i = 0; i < m.groupCount(); i++) paramHash.put((String) paramList.get(i), m.group(i + 1)); } //special handling of Organizational Unit Feed //TODO: should be resolved other way! if (getUriMatcher().equals("(.+)?/syndication/feed/(.+)?/publications/organization/(.+)?")) { TreeMap<String, String> outm = Utils.getOrganizationUnitTree(); String oid = (String) paramHash.get("${organizationId}"); for (Map.Entry<String, String> entry : outm.entrySet()) { if (entry.getValue().equals(oid)) { paramHash.put("${organizationName}", entry.getKey()); } } } logger.info("parameters: " + paramHash); }
From source file:br.com.bropenmaps.util.Util.java
/** * Verifica se duas strings so iguais independentemente da caixa e dos acentos * @param p1/*from w ww . j a v a 2 s . co m*/ * @param p2 * @return true se so iguais, false em caso contrrio */ public static boolean verificaIgualdadeCaseInsensitiveSemAcento(String p1, String p2) { if (p1 == null || p2 == null) { return false; } p1 = regExpPalavrasAcentuadas(StringUtils.lowerCase(p1)); final Pattern p = Pattern.compile(p1, Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(p2); if (m.find()) { return true; } else { return false; } }
From source file:br.com.blackhubos.eventozero.util.Framework.java
/** * Transforma uma string no formato XhYmZs (ex: 15h30m55s) em um long para ser usado em bukkit schedulers. * * @param tempo A string em formato XhYmZs. * @return retorna o tempo convertido para long (*20L). *//*from w w w.j a v a 2 s . c om*/ public static long reverseOf(final String tempo) { if (tempo == null) { return 0L; } final Pattern verifier = Pattern.compile("(([0-9]+)(h|m|s))", Pattern.CASE_INSENSITIVE); final Matcher m = verifier.matcher(tempo.toLowerCase()); long delay = 0L; while (m.find()) { final int numero = Framework.getInt(m.group(2)); final char c = m.group(3).charAt(0); if (c == 's') { delay += numero * 20L; } else if (c == 'm') { delay += (numero * 60) * 20L; } else if (c == 'h') { delay += ((numero * 60) * 20L) * 60; } } return delay; }
From source file:de.zib.gndms.common.rest.UriFactory.java
public static Specifier<Void> parseSliceKindSpecifier(final String uri) { Pattern pattern = Pattern.compile("(.*)/dspace/_([^/]+)/_([^/]+)/?", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(uri); if (matcher.matches()) return createSliceKindSpecifier(matcher.group(1), matcher.group(2), matcher.group(3)); else/* w w w .j a v a2 s.c om*/ throw new IllegalArgumentException("URL describes no valid SliceKind specifier: " + uri); }
From source file:net.issarlk.androbunny.inkbunny.API.java
public void scrapeUserPage(User argUser) throws IOException { argUser.profile = "Couldn't read user profile"; String data = ""; try {//from www . j a v a 2 s . co m data = AndrobunnyAppSingleton.androbunnyapp.readUri(new URI("https://inkbunny.net/" + argUser.name)); } catch (URISyntaxException e2) { Log.e(TAG, e2.toString()); } // Extract profile Pattern pattern = Pattern.compile(".*<div class='title'>Profile</div>.*?(<.*)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); argUser.profile = extractTree(pattern, data); // Extract user icon pattern = Pattern.compile( "<img [^>]*? src='([^']*)' [^>]*? alt='" + argUser.name + "' title='" + argUser.name + "'[^>]*?/>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher matcher = pattern.matcher(data); if (matcher.find()) { //Found the user icon try { argUser.icons[0] = new Icon(Icon.LARGE, new URI(matcher.group(1))); } catch (URISyntaxException e) { Log.e(TAG, e.toString()); } } }
From source file:com.untangle.app.branding_manager.BrandingManagerApp.java
/** * Using the non-branded version from uvm as a template base, modify * images and text to reflect branding.// www.ja v a 2 s. co m */ private void createRootCaInstaller() { /* * Use the non-branded version as a template base. Copy over. */ UvmContextFactory.context().execManager().exec("rm -rf " + ROOT_CA_INSTALLER_DIRECTORY_NAME + "; cp -fa " + CertificateManager.ROOT_CA_INSTALLER_DIRECTORY_NAME + " " + ROOT_CA_INSTALLER_DIRECTORY_NAME); /* * Convert images to .bmp format */ UvmContextFactory.context().execManager().exec("anytopnm " + BRANDING_LOGO + " | ppmtobmp > " + ROOT_CA_INSTALLER_DIRECTORY_NAME + "/images/modern-header.bmp"); UvmContextFactory.context().execManager().exec("anytopnm " + BRANDING_LOGO + " | pnmrotate 90 | ppmtobmp > " + ROOT_CA_INSTALLER_DIRECTORY_NAME + "/images/modern-wizard.bmp"); /* * Parse files replacing Untangle defaults */ String companyName = settings.getCompanyName(); String companyUrl = settings.getCompanyUrl(); for (Map.Entry<FILE_PARSE_TYPE, String> filenameSet : ROOT_CA_INSTALLER_PARSE_FILE_NAMES.entrySet()) { String filename = filenameSet.getValue(); File file = new File(filename); String name = file.getName(); HashMap<REGEX_TYPE, Pattern> regexes = new HashMap<>(); String quotedString = ""; int flags = 0; if (filenameSet.getKey() == FILE_PARSE_TYPE.QUOTED) { quotedString = "\""; } else { flags = Pattern.CASE_INSENSITIVE; } /* * Build up regexes to find the first occurance of our current name. */ regexes.put(REGEX_TYPE.COMPANY_NAME, Pattern.compile( "(" + quotedString + ".*?)" + DEFAULT_UNTANGLE_COMPANY_NAME + "(.*" + quotedString + ")", flags)); regexes.put(REGEX_TYPE.COMPANY_URL, Pattern.compile( "(" + quotedString + ".*?)" + "http://.*.untangle.com(.*" + quotedString + ")", flags)); StringBuilder parsed = new StringBuilder(); Matcher match = null; BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(filename)); for (String line = reader.readLine(); null != line; line = reader.readLine()) { /* * When parsing the nsi file we only want to replace strings within quotes and * for other files, everything. */ for (Map.Entry<REGEX_TYPE, Pattern> regex : regexes.entrySet()) { match = regex.getValue().matcher(line); int startPos = 0; while (match.find(startPos)) { switch (regex.getKey()) { case COMPANY_NAME: startPos = match.start() + match.group(1).length() + companyName.length(); line = match.replaceAll("$1" + companyName + "$2"); break; case COMPANY_URL: startPos = match.start() + match.group(1).length() + companyUrl.length(); line = match.replaceAll("$1" + companyUrl + "$2"); break; default: /* Shouldn'e be here...but if we are, make sure we exit the loop. */ startPos = line.length(); } if (startPos >= line.length()) { break; } match = regex.getValue().matcher(line); } } parsed.append(line).append(EOL); } } catch (Exception x) { logger.warn("Unable to open installer configuration file: " + filename); return; } finally { if (reader != null) { try { reader.close(); } catch (Exception x) { logger.warn("Unable to close installer configuration file: " + filename); } } } FileOutputStream fos = null; File tmp = null; try { tmp = File.createTempFile(file.getName(), ".tmp"); fos = new FileOutputStream(tmp); fos.write(parsed.toString().getBytes()); fos.flush(); fos.close(); IOUtil.copyFile(tmp, new File(filename)); tmp.delete(); } catch (Exception ex) { IOUtil.close(fos); tmp.delete(); logger.error("Unable to create installer file:" + filename + ":", ex); } } /* * Regenerate */ UvmContextFactory.context().execManager().exec(CertificateManager.ROOT_CA_INSTALLER_SCRIPT); }
From source file:com.redhat.rhn.manager.kickstart.ProvisionVirtualInstanceCommand.java
/** * {@inheritDoc}//from w w w.j a v a2 s. co m */ public ValidatorError doValidation() { if (guestName.length() < MIN_NAME_SIZE) { return new ValidatorError("frontend.actions.systems.virt.invalidguestnamelength", MIN_NAME_SIZE); } Pattern pattern = Pattern.compile(GUEST_NAME_REGEXP, Pattern.CASE_INSENSITIVE); if (!pattern.matcher(guestName).matches()) { return new ValidatorError("frontend.actions.systems.virt.invalidregexp"); } if (virtualCpus <= 0 || virtualCpus > ProvisionVirtualInstanceCommand.MAX_CPU) { return new ValidatorError("frontend.actions.systems.virt.invalidcpuvalue", MAX_CPU + 1); } return super.doValidation(); }
From source file:com.sittinglittleduck.DirBuster.Worker.java
private void verifyResponseForValidRequests(int code, String response, String rawResponse) { if (Config.debug) { System.out.println("DEBUG Worker[" + threadId + "]: Base Case Check " + url.toString()); }//ww w . j a v a 2 s .co m // TODO move this option to the Adv options // if the response does not match the base case Pattern regexFindFile = Pattern.compile(".*file not found.*", Pattern.CASE_INSENSITIVE); Matcher m = regexFindFile.matcher(response); // need to clean the base case of the item we are looking for String basecase = FilterResponce.removeItemCheckedFor(work.getBaseCaseObj().getBaseCase(), work.getItemToCheck()); if (m.find()) { System.out.println("DEBUG Worker[" + threadId + "]: 404 for: " + url.toString()); } else if (!response.equalsIgnoreCase(basecase)) { notifyItemFound(code, response, rawResponse, basecase); } }