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.g3net.tool.StringUtils.java
public static int indexOf(String srcStr, String regexp, boolean ignoreCase, TInteger endPos) { Pattern p = null;/*from w w w . j a va 2 s. c om*/ if (ignoreCase) { p = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE); } else { p = Pattern.compile(regexp); } Matcher m = p.matcher(srcStr); int startPos = -1; while (m.find()) { // log.info(m.group()+":"+m.start()+":"+m.end()); startPos = m.start(); endPos.setValue(m.end()); return startPos; } return -1; // sql3.regionMatches(ignoreCase, toffset, other, ooffset, len) // log.info(m.matches()); }
From source file:edu.temple.cis3238.wiki.utils.StringUtils.java
/** * Removes all html tags from string//from w w w .ja v a 2 s . c o m * * @param val * @return */ public static String removeHtmlMarkups(String val) { String clean = ""; try { Pattern pattern = Pattern.compile(REGEX_HTML_MARKUP_CHARS, Pattern.DOTALL | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); Matcher matcher = pattern.matcher(val); try { clean = matcher.replaceAll(""); } catch (IllegalArgumentException ex) { } catch (IndexOutOfBoundsException ex) { } } catch (PatternSyntaxException ex) { } // return toS(clean); }
From source file:com.opengamma.bbg.util.BloombergDataUtils.java
private static Pattern buildPattern() { if (BloombergConstants.MARKET_SECTORS.isEmpty()) { throw new OpenGammaRuntimeException("Bloomberg market sectors can not be empty"); }/*from ww w . ja v a 2 s . c o m*/ final List<String> marketSectorList = Lists.newArrayList(BloombergConstants.MARKET_SECTORS); String sectorPattern = marketSectorList.get(0); for (int i = 1; i < marketSectorList.size(); i++) { sectorPattern += "|" + marketSectorList.get(i); } final Pattern bloombergTickerPattern = Pattern.compile(String.format("^(.+)(\\s+)((%s))$", sectorPattern), Pattern.CASE_INSENSITIVE); return bloombergTickerPattern; }
From source file:DataBase.DataBase.java
public static ArrayList<NetworkInfo> getNetworkStats() { if (!DataBase.cellRead()) { DataBase.readCell();//from w w w . j a va 2 s. c om } HashMap<String, NetworkInfo> info = new HashMap<String, NetworkInfo>(); info.put("Cosmote", new NetworkInfo("Cosmote")); info.put("Vodafone", new NetworkInfo("Vodafone")); info.put("Wind", new NetworkInfo("Wind")); info.put("Orange", new NetworkInfo("Orange")); info.put("Sunrise", new NetworkInfo("Sunrise")); // HashMap<String,String> loggedUsers = new HashMap<String,String>(); for (CellRec c : DataBase.getAllCell()) { // if(loggedUsers.get(c.getId())!=null) // continue; // loggedUsers.put(c.getId(),c.getId()); //Cosmote Pattern C = Pattern.compile("co", Pattern.CASE_INSENSITIVE); Matcher Cm = C.matcher(c.getOperator()); if (Cm.find()) { NetworkInfo inf = info.get("Cosmote"); if (inf.users.get(c.getId()) == null) { inf.number++; inf.users.put(c.getId(), c.getId()); } continue; } //Vodafone Pattern V = Pattern.compile("vod", Pattern.CASE_INSENSITIVE); Matcher Vm = V.matcher(c.getOperator()); if (Vm.find()) { NetworkInfo inf = info.get("Vodafone"); if (inf.users.get(c.getId()) == null) { inf.number++; inf.users.put(c.getId(), c.getId()); } continue; } //CU Pattern Cx = Pattern.compile("CU", Pattern.CASE_INSENSITIVE); Matcher Cxm = Cx.matcher(c.getOperator()); if (Cxm.find()) { NetworkInfo inf = info.get("Vodafone"); if (inf.users.get(c.getId()) == null) { inf.number++; inf.users.put(c.getId(), c.getId()); } continue; } //Wind Pattern W = Pattern.compile("wi", Pattern.CASE_INSENSITIVE); Matcher Wm = W.matcher(c.getOperator()); if (Wm.find()) { NetworkInfo inf = info.get("Wind"); if (inf.users.get(c.getId()) == null) { inf.number++; inf.users.put(c.getId(), c.getId()); } continue; } //Sunrise Pattern S = Pattern.compile("sun", Pattern.CASE_INSENSITIVE); Matcher Sm = S.matcher(c.getOperator()); if (Sm.find()) { NetworkInfo inf = info.get("Sunrise"); if (inf.users.get(c.getId()) == null) { inf.number++; inf.users.put(c.getId(), c.getId()); } continue; } //Orange Pattern O = Pattern.compile("Orange F", Pattern.CASE_INSENSITIVE); Matcher Om = O.matcher(c.getOperator()); if (Om.find()) { NetworkInfo inf = info.get("Orange"); if (inf.users.get(c.getId()) == null) { inf.number++; inf.users.put(c.getId(), c.getId()); } continue; } } ArrayList<NetworkInfo> info2 = new ArrayList<NetworkInfo>(); Iterator it = info.entrySet().iterator(); while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); info2.add((NetworkInfo) pair.getValue()); } return info2; }
From source file:com.ponysdk.impl.query.memory.FilteringTools.java
/** * Used to Filter a list of data, scoped by a <code>propertyPath</code>, * according to a <code>patternName</code>. The property path is used to go * as deep as one wants into each object of the <code>datas</code>. It takes * form as a string representing attributes separated by dots, e.g. * <code>attribute1.attribute2.attribute3</code><br/> * <br/>//from w w w . j ava 2 s . co m * If an attribute is a map, the tokens <code>keys</code> or * <code>values</code> can be used to retrieve the corresponding data as a * Collection. E.g. <code>attribute1.mapAttribute.keys.attribute2</code> * * @param <T> * the type of the data obtained with the propertyPath that is * tested against the patternName * @param datas * the list of data to be filtered * @param propertyPath * the chain of attribute representing a path deep into the data * objects * @param patternName * a string used to filter data * @return the list of filtered data */ public static <T> List<T> filter(final List<T> datas, final String propertyPath, final String patternName) { if (datas == null || patternName.equals(EMPTY) || propertyPath.equals(EMPTY)) { return datas; } final List<T> validData = new ArrayList<>(); try { final String[] pathDetails = propertyPath.split(DOT_REGEX); for (final T data : datas) { final Object val = getValue(data, pathDetails); if (val == null) continue; // Now we can filter our data against the pattern final String value = normalisePattern(patternName.trim()); final Pattern pattern = Pattern.compile(REGEX_BEGIN + value + REGEX_END, Pattern.CASE_INSENSITIVE); Matcher matcher; if (val instanceof Collection<?>) { final Collection<?> collection = (Collection<?>) val; for (final Object item : collection) { matcher = pattern.matcher(item.toString()); if (matcher.find()) { validData.add(data); break; } } if (collection.isEmpty()) { matcher = pattern.matcher(""); if (matcher.find()) { validData.add(data); } } } else if (val.toString() != null) { matcher = pattern.matcher(val.toString()); if (matcher.find()) { validData.add(data); } else { matcher = pattern.matcher(""); if (matcher.find()) { validData.add(data); } } } } } catch (final PatternSyntaxException e) { if (log.isDebugEnabled()) { log.debug("bad pattern : " + patternName); } } catch (final Exception e) { log.error("Filter Error => pattern : " + patternName + " , property : " + propertyPath, e); } return validData; }
From source file:com.github.thorqin.toolkit.mail.MailService.java
public static Mail createMailByTemplateStream(InputStream in, Map<String, String> replaced) throws IOException { Mail mail = new Mail(); InputStreamReader reader = new InputStreamReader(in, "utf-8"); char[] buffer = new char[1024]; StringBuilder builder = new StringBuilder(); while (reader.read(buffer) != -1) builder.append(buffer);/* w w w.j av a 2 s .c o m*/ String mailBody = builder.toString(); builder.setLength(0); Pattern pattern = Pattern.compile("<%\\s*(.+?)\\s*%>", Pattern.MULTILINE); Matcher matcher = pattern.matcher(mailBody); int scanPos = 0; while (matcher.find()) { builder.append(mailBody.substring(scanPos, matcher.start())); scanPos = matcher.end(); String key = matcher.group(1); if (replaced != null) { String value = replaced.get(key); if (value != null) { builder.append(value); } } } builder.append(mailBody.substring(scanPos, mailBody.length())); mail.htmlBody = builder.toString(); pattern = Pattern.compile("<title>(.*)</title>", Pattern.MULTILINE | Pattern.DOTALL | Pattern.CASE_INSENSITIVE); matcher = pattern.matcher(mail.htmlBody); if (matcher.find()) { mail.subject = matcher.group(1); } return mail; }
From source file:com.orion.console.UrT42Console.java
/** * Return a <tt>Map</tt> with all the CVARs set on the server * //from ww w . j a v a2 s . co m * @author Daniele Pantaleone * @param match A pattern to be used to short the <tt>Cvar</tt> list * @throws RconException If the <tt>Cvar</tt> list couldn't be retrieved from the server * @return A <tt>Map</tt> with all the CVARs set on the server **/ public Map<String, Cvar> getCvarList(String match) throws RconException { // convert to empty if null given match = match != null ? match : ""; String result = this.write("cvarlist " + match, true); Map<String, Cvar> cvarList = new HashMap<String, Cvar>(); Pattern pattern = Pattern.compile("^.{7} (?<name>\\s*\\w+)\\s+\"(?<value>.*)\"$", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(result); while (matcher.find()) { String n = matcher.group("name").toLowerCase(); String v = matcher.group("value"); if (!n.trim().isEmpty() && !v.trim().isEmpty()) cvarList.put(n, new Cvar(n, v)); } // leave a trace in the log so we know how many CVARs we retrieved this.log.trace("Retrieved " + cvarList.size() + " CVARs from the server"); return cvarList; }
From source file:net.sf.jabref.external.RegExpFileSearch.java
/** * The actual work-horse. Will find absolute filepaths starting from the * given directory using the given regular expression string for search. *//*from www . java 2 s . c o m*/ private static List<File> findFile(BibEntry entry, File directory, String file, String extensionRegExp) { List<File> res = new ArrayList<>(); File actualDirectory; if (file.startsWith("/")) { actualDirectory = new File("."); file = file.substring(1); } else { actualDirectory = directory; } // Escape handling... Matcher m = ESCAPE_PATTERN.matcher(file); StringBuffer s = new StringBuffer(); while (m.find()) { m.appendReplacement(s, m.group(1) + '/' + m.group(2)); } m.appendTail(s); file = s.toString(); String[] fileParts = file.split("/"); if (fileParts.length == 0) { return res; } for (int i = 0; i < (fileParts.length - 1); i++) { String dirToProcess = fileParts[i]; dirToProcess = expandBrackets(dirToProcess, entry, null); if (dirToProcess.matches("^.:$")) { // Windows Drive Letter actualDirectory = new File(dirToProcess + '/'); continue; } if (".".equals(dirToProcess)) { // Stay in current directory continue; } if ("..".equals(dirToProcess)) { actualDirectory = new File(actualDirectory.getParent()); continue; } if ("*".equals(dirToProcess)) { // Do for all direct subdirs File[] subDirs = actualDirectory.listFiles(); if (subDirs != null) { String restOfFileString = StringUtil.join(fileParts, "/", i + 1, fileParts.length); for (File subDir : subDirs) { if (subDir.isDirectory()) { res.addAll(findFile(entry, subDir, restOfFileString, extensionRegExp)); } } } } // Do for all direct and indirect subdirs if ("**".equals(dirToProcess)) { List<File> toDo = new LinkedList<>(); toDo.add(actualDirectory); String restOfFileString = StringUtil.join(fileParts, "/", i + 1, fileParts.length); while (!toDo.isEmpty()) { // Get all subdirs of each of the elements found in toDo File[] subDirs = toDo.remove(0).listFiles(); if (subDirs == null) { continue; } toDo.addAll(Arrays.asList(subDirs)); for (File subDir : subDirs) { if (!subDir.isDirectory()) { continue; } res.addAll(findFile(entry, subDir, restOfFileString, extensionRegExp)); } } } // End process directory information } // Last step: check if the given file can be found in this directory String filePart = fileParts[fileParts.length - 1].replace("[extension]", EXT_MARKER); String filenameToLookFor = expandBrackets(filePart, entry, null).replaceAll(EXT_MARKER, extensionRegExp); final Pattern toMatch = Pattern.compile('^' + filenameToLookFor.replaceAll("\\\\\\\\", "\\\\") + '$', Pattern.CASE_INSENSITIVE); File[] matches = actualDirectory.listFiles((arg0, arg1) -> { return toMatch.matcher(arg1).matches(); }); if ((matches != null) && (matches.length > 0)) { Collections.addAll(res, matches); } return res; }
From source file:com.liferay.ide.project.core.tests.UpgradeLiferayProjectsOpTests.java
private String getNewDoctTypeSetting(String doctypeSetting, String regrex) { Pattern p = Pattern.compile(regrex, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher m = p.matcher(doctypeSetting); if (m.find()) { return m.group(m.groupCount()); }/*from w ww . j a v a 2 s.c om*/ return null; }
From source file:br.com.cobranca.util.Util.java
/** * Metodo que valida email//from w w w . j a va 2 s .com * * @param email * @return */ public static boolean isEmailValido(String email) { if ((email == null) || (email.trim().length() == 0)) { return false; } String emailPattern = "\\b(^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\\.[A-Za-z0-9-]+)*((\\.[A-Za-z0-9]{2,})|(\\.[A-Za-z0-9]{2,}\\.[A-Za-z0-9]{2,}))$)\\b"; Pattern pattern = Pattern.compile(emailPattern, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(email); return matcher.matches(); }