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.enonic.cms.business.localization.resource.LocalizationResourceBundleUtils.java
public static Locale parseLocaleString(String localeAsString) { localeAsString = localeAsString.replace('-', '_'); Matcher matcher = RegexpUtil.match(localeAsString, LOCALE_PATTERN, Pattern.CASE_INSENSITIVE); String language = ""; String country = ""; String variant = ""; if (matcher.matches()) { language = getLanguageFromMatcher(matcher); country = getCountryFromMatcher(matcher); variant = getVariantFromMatcher(matcher); } else {//from w w w . j a v a2s. co m throw new LocaleParsingException( "Could not parse locale string: " + localeAsString + " to valid locale"); } return new Locale(language, country == null ? "" : country, variant == null ? "" : variant); }
From source file:Main.java
public static boolean isLinkAvailable(String link) { Pattern pattern = Pattern.compile( "^(http://|https://)?((?:[A-Za-z0-9]+-[A-Za-z0-9]+|[A-Za-z0-9]+)\\.)+([A-Za-z]+)[/\\?\\:]?.*$", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(link); if (matcher.matches()) { return true; }/*from w w w .j a va 2 s. co m*/ return false; }
From source file:Main.java
/** * Creates a regular expression pattern that matches a "wildcard" pattern. * /* w w w . j a v a 2s. co m*/ * @param wildcard The wildcard pattern. * @param matchCase Whether the pattern should be case sensitive. * @param escapeStartChar Whether to escape a starting <code>'^'</code> * character. * @return The pattern. */ public static Pattern wildcardToPattern(String wildcard, boolean matchCase, boolean escapeStartChar) { int flags = 0; if (!matchCase) { flags = Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE; } StringBuffer sb = new StringBuffer(); for (int i = 0; i < wildcard.length(); i++) { char ch = wildcard.charAt(i); switch (ch) { case '*': sb.append(".*"); break; case '?': sb.append('.'); break; case '^': if (i > 0 || escapeStartChar) { sb.append('\\'); } sb.append('^'); break; case '\\': case '.': case '|': case '+': case '-': case '$': case '[': case ']': case '{': case '}': case '(': case ')': sb.append('\\').append(ch); break; default: sb.append(ch); break; } } Pattern p = null; try { p = Pattern.compile(sb.toString(), flags); } catch (PatternSyntaxException pse) { pse.printStackTrace(); p = Pattern.compile(".+"); } return p; }
From source file:Main.java
/** * Creates a map of tag name to clean header XML by running a substitution * regex on each entry of tag to dirty header XML. * * @param dirtyXmlMap a map of tag name to dirty header XML * @return a map of tag name to clean header XML *//*from w w w .ja v a 2 s .c om*/ private static Map<String, String> createTagToCleanXmlMap(Map<String, String> dirtyXmlMap) { Map<String, String> cleanXmlMap = new HashMap<String, String>(); for (Entry<String, String> sensitiveXml : dirtyXmlMap.entrySet()) { Pattern p = Pattern.compile( String.format(SENSITIVE_REGEX, sensitiveXml.getKey(), sensitiveXml.getKey()), Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher m = p.matcher(sensitiveXml.getValue()); if (m.matches()) { cleanXmlMap.put(sensitiveXml.getKey(), m.replaceFirst("$1******$2")); } } return cleanXmlMap; }
From source file:Main.java
/** * Compiles the given regular expression into a Pattern that may or may not be case-sensitive, depending on the regular expression. * If the regular expression contains any capital letter, that is assumed to be meaningful, and the resulting Pattern is case-sensitive. * If the whole regular expression is lower-case, the resulting Pattern is case-insensitive. * /*w ww. j a v a 2 s . com*/ * This is useful for implementing functionality like emacs/vim's "smart case", hence the name. * * By default, we enable (?m) on the assumption that it's more useful if ^ and $ match the start and end of each line rather than just the start and end of input. */ public static Pattern smartCaseCompile(String regularExpression) { boolean caseInsensitive = true; for (int i = 0; i < regularExpression.length(); ++i) { if (Character.isUpperCase(regularExpression.charAt(i))) { caseInsensitive = false; } } int flags = Pattern.MULTILINE; if (caseInsensitive) { flags |= Pattern.CASE_INSENSITIVE; } return Pattern.compile(regularExpression, flags); }
From source file:morphy.utils.RegExUtils.java
public static Pattern getPattern(String regularExpression) { return Pattern.compile(regularExpression, Pattern.MULTILINE | Pattern.DOTALL | Pattern.CASE_INSENSITIVE); }
From source file:Main.java
public static int getLengthOfLongestWord(String string) { int longestWordLength = 0; Matcher m = Pattern.compile("\\s*(\\S+)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE).matcher(string); while (m.find()) { longestWordLength = Math.max(longestWordLength, m.group(1).length()); }/*from ww w . ja va 2s. c o m*/ return longestWordLength; }
From source file:Main.java
public static String getYoutubeVideoId(String in) { //*EDIT* - fixed to hopefully support more recent youtube link styles/formats: final String pattern = "(?<=watch\\?v=|/videos/|/embed/|youtu.be/)[^&#?]*"; final String pattern2 = "(?:youtube(?:-nocookie)?\\.com\\/(?:[^\\/\\n\\s]+\\/\\S+\\/|(?:v|e(?:mbed)?)\\/|\\S*?[?&]v=)|youtu\\.be\\/)([a-zA-Z0-9_-]{11})"; Pattern compiledPattern = Pattern.compile(pattern2, Pattern.CASE_INSENSITIVE); Matcher matcher = compiledPattern.matcher(in); if (matcher.find()) { return matcher.group(1); }/* w w w .j a v a2s .co m*/ return null; }
From source file:Main.java
public static boolean isFindHttpAtPrefixs(String _url) { Pattern pattern = Pattern.compile("^http://", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(_url.toLowerCase()); return matcher.find(); }
From source file:Main.java
public static boolean isFindHttpsAtPrefixs(String _url) { Pattern pattern = Pattern.compile("^https://", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(_url.toLowerCase()); return matcher.find(); }