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:Main.java
private static String replaceAll(final String regex, final String text, final String replacement) { final Pattern compiledRegex = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); return compiledRegex.matcher(text).replaceAll(replacement); }
From source file:Main.java
/** * get innerHtml from href/* ww w .j a v a2s. com*/ * * <pre> * getHrefInnerHtml(null) = "" * getHrefInnerHtml("") = "" * getHrefInnerHtml("mp3") = "mp3"; * getHrefInnerHtml("<a innerHtml</a>") = "<a innerHtml</a>"; * getHrefInnerHtml("<a>innerHtml</a>") = "innerHtml"; * getHrefInnerHtml("<a<a>innerHtml</a>") = "innerHtml"; * getHrefInnerHtml("<a href="baidu.com">innerHtml</a>") = "innerHtml"; * getHrefInnerHtml("<a href="baidu.com" title="baidu">innerHtml</a>") = "innerHtml"; * getHrefInnerHtml(" <a>innerHtml</a> ") = "innerHtml"; * getHrefInnerHtml("<a>innerHtml</a></a>") = "innerHtml"; * getHrefInnerHtml("jack<a>innerHtml</a></a>") = "innerHtml"; * getHrefInnerHtml("<a>innerHtml1</a><a>innerHtml2</a>") = "innerHtml2"; * </pre> * * @param href * @return <ul> * <li>if href is null, return ""</li> * <li>if not match regx, return source</li> * <li>return the last string that match regx</li> * </ul> */ public static String getHrefInnerHtml(String href) { if (isEmpty(href)) { return ""; } String hrefReg = ".*<[\\s]*a[\\s]*.*>(.+?)<[\\s]*/a[\\s]*>.*"; Pattern hrefPattern = Pattern.compile(hrefReg, Pattern.CASE_INSENSITIVE); Matcher hrefMatcher = hrefPattern.matcher(href); if (hrefMatcher.matches()) { return hrefMatcher.group(1); } return href; }
From source file:com.titankingdoms.dev.titanchat.format.Censor.java
/** * Filters the text for phrases and censors the phrases with the censor * /* w w w .jav a 2 s.c om*/ * @param text The text to filter * * @param phrases The phrases to censor * * @param censor The censor to use * * @return The filtered text */ public static String filter(String text, List<String> phrases, String censor) { if (text == null) return ""; if (phrases == null) return text; if (censor == null) censor = ""; StringBuffer filtered = new StringBuffer(); String regex = "(" + StringUtils.join(phrases.toArray(new String[0])) + ")"; Pattern phrasePattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher match = phrasePattern.matcher(text); while (match.find()) match.appendReplacement(filtered, Pattern.compile(".").matcher(match.group()).replaceAll(censor)); return match.appendTail(filtered).toString(); }
From source file:commonUtils.CommonUtils.java
public static boolean IsValidEmailAddress(String emailAddress) { String expression = "^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Z]{2,4}$"; CharSequence inputStr = emailAddress; Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(inputStr); return matcher.matches(); }
From source file:edu.indiana.lib.twinpeaks.util.StringUtils.java
/** * Replace all occurances of the target text with the provided replacement * text. Both target and replacement may be regular expressions - see * <code>java.util.regex.Matcher</code>. * @param text Text to modify/*from w ww .jav a 2 s .c o m*/ * @param targetText Text to find and replace * @param newText New text * @return Updated text */ public static String replace(String text, String targetText, String newText) { Pattern pattern = Pattern.compile(targetText, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(text); return matcher.replaceAll(newText); }
From source file:com.ibm.watson.catalyst.corpus.tfidf.Template.java
public static Pattern getTemplatePattern(JsonNode document, String before, String after) { JsonNode terms = document.get("words"); List<String> words = new ArrayList<String>(); for (JsonNode termNode : terms) { if (termNode.get("frequency").asInt() < 5) continue; if (termNode.get("string").asText().length() < 2) continue; Term t = new Term(termNode); words.add(t.getTerm());// w ww . ja v a 2s .c o m } StringBuffer sb = new StringBuffer(""); sb.append(before).append(makeOr(words)).append(after); Pattern p = Pattern.compile(sb.toString(), Pattern.CASE_INSENSITIVE); return p; }
From source file:gsn.storage.SQLUtils.java
/** * Table renaming, note that the renameMapping should be a tree map. This * method gets a sql query and changes the table names using the mappings * provided in the second argument.<br> * // w w w . jav a 2s .c om * @param query * @param renameMapping * @return */ public static StringBuilder newRewrite(CharSequence query, TreeMap<CharSequence, CharSequence> renameMapping) { // Selecting strings between pair of "" : (\"[^\"]*\") // Selecting tableID.tableName or tableID.* : (\\w+(\\.(\w+)|\\*)) // The combined pattern is : (\"[^\"]*\")|(\\w+\\.((\\w+)|\\*)) Pattern pattern = Pattern.compile("(\"[^\"]*\")|((\\w+)(\\.((\\w+)|\\*)))", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(query); StringBuffer result = new StringBuffer(); if (!(renameMapping.comparator() instanceof CaseInsensitiveComparator)) throw new RuntimeException("Query rename needs case insensitive treemap."); while (matcher.find()) { if (matcher.group(2) == null) continue; String tableName = matcher.group(3); CharSequence replacement = renameMapping.get(tableName); // $4 means that the 4th group of the match should be appended to the // string (the forth group contains the field name). if (replacement != null) matcher.appendReplacement(result, new StringBuilder(replacement).append("$4").toString()); } String toReturn = matcher.appendTail(result).toString().toLowerCase(); //TODO " from " has to use regular expressions because now from is separated through space which is not always the case, for instance if the user uses \t(tab) for separating "from" from the rest of the query, then we get exception. The same issue with other sql keywords in this method. int indexOfFrom = toReturn.indexOf(" from ") >= 0 ? toReturn.indexOf(" from ") + " from ".length() : 0; int indexOfWhere = (toReturn.lastIndexOf(" where ") > 0 ? (toReturn.lastIndexOf(" where ")) : toReturn.length()); String selection = toReturn.substring(indexOfFrom, indexOfWhere); Pattern fromClausePattern = Pattern.compile("\\s*(\\w+)\\s*", Pattern.CASE_INSENSITIVE); Matcher fromClauseMather = fromClausePattern.matcher(selection); result = new StringBuffer(); while (fromClauseMather.find()) { if (fromClauseMather.group(1) == null) continue; String tableName = fromClauseMather.group(1); CharSequence replacement = renameMapping.get(tableName); if (replacement != null) fromClauseMather.appendReplacement(result, replacement.toString() + " "); } String cleanFromClause = fromClauseMather.appendTail(result).toString(); String finalResult = StringUtils.replace(toReturn, selection, cleanFromClause); return new StringBuilder(finalResult); }
From source file:Main.java
public static SpannableString toSpannableString(Context context, String text, SpannableString spannableString) { int start = 0; Pattern pattern = Pattern.compile("\\\\ue[a-z0-9]{3}", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(text); while (matcher.find()) { String faceText = matcher.group(); String key = faceText.substring(1); BitmapFactory.Options options = new BitmapFactory.Options(); // options.inSampleSize = 2; Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), context.getResources().getIdentifier(key, "drawable", context.getPackageName()), options); ImageSpan imageSpan = new ImageSpan(context, bitmap); int startIndex = text.indexOf(faceText, start); int endIndex = startIndex + faceText.length(); if (startIndex >= 0) spannableString.setSpan(imageSpan, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); start = (endIndex - 1);/* w w w. jav a2s . c o m*/ } return spannableString; }
From source file:com.sap.prd.mobile.ios.mios.XCodeVersionUtil.java
public static DefaultArtifactVersion getVersion(String xCodeVersionString) throws XCodeException { Pattern versionPattern = Pattern.compile("Xcode (\\d+(\\.\\d+)+)", Pattern.CASE_INSENSITIVE); Matcher versionMatcher = versionPattern.matcher(xCodeVersionString); if (versionMatcher.find()) { return new DefaultArtifactVersion(versionMatcher.group(1)); }/*from w w w . j a va 2 s .c om*/ throw new XCodeException("Could not get xcodebuild version"); }
From source file:edu.temple.cis3238.wiki.utils.FileUtils.java
/** * Verifies valid file extension//from ww w. ja va 2 s . co m * @param filePath full path of file * @param extraValidExtensions CSV list of additional valid file extensions. * @return valid * @see edu.temple.cis3238.wiki.ui.servlets.UploadServlet */ public static boolean checkFileExtension(String filePath, String extraValidExtensions) { String[] extensionArray = { "" }; String extensions = ""; if (extraValidExtensions != null && !extraValidExtensions.isEmpty()) { extensionArray = extraValidExtensions.replace(" ", "").toLowerCase().split(","); extensions = "|" + org.apache.commons.lang3.StringUtils.join(extensionArray, '|'); extensions = org.apache.commons.lang3.StringUtils.removeEnd(extensions.trim(), "|"); } File file = new File(filePath); String validExts = "(pdf|mp4|m4v|wmv|flv|swf|avi|mov|mpeg|mpg|mov|doc|docx|xls|xlsx|ppt|pptx|txt|jpg|jpeg|png" + extensions + ")"; // if (!file.isFile()) { // return false; // } // else { String type = filePath.substring(filePath.lastIndexOf(".") + 1, filePath.length()).toLowerCase(); try { Pattern regex = Pattern.compile(validExts, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); Matcher regexMatcher = regex.matcher(type); if (regexMatcher.matches()) { return true; } } catch (PatternSyntaxException ex) { LOG.log(Level.SEVERE, null, ex); return false; } // } return false; }