Example usage for java.util.regex Pattern CASE_INSENSITIVE

List of usage examples for java.util.regex Pattern CASE_INSENSITIVE

Introduction

In this page you can find the example usage for java.util.regex Pattern CASE_INSENSITIVE.

Prototype

int CASE_INSENSITIVE

To view the source code for java.util.regex Pattern CASE_INSENSITIVE.

Click Source Link

Document

Enables case-insensitive matching.

Usage

From source file:Main.java

public static List<String> getImageUrls(String content) {
    List<String> result = new ArrayList<String>();
    Pattern pattern = Pattern.compile(REGEX_MATCH_IMAGE, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(content);

    while (matcher.find()) {
        String group = matcher.group(1);
        if (group != null) {
            result.add(group);/*from  w  w  w. ja  v a  2 s  .c o m*/
        }
    }
    return result;
}

From source file:Main.java

/**
 * Check whether the target string contains the indicated sub string, and case insensitive
 * // w  w  w  . ja  va 2s.co  m
 * @param target  the target string
 * @param subStr  the sub string
 * @return the check result
 */
public static boolean containsIgnoreCase(String target, String subStr) {
    target = deNull(target);
    subStr = deNull(subStr);

    return Pattern.compile(Pattern.quote(subStr), Pattern.CASE_INSENSITIVE).matcher(target).find();
}

From source file:Main.java

/**
 * Regex matcher for PART X pattern in multi-part videos
 * http://txt2re.com/index-java.php3/*from  ww  w  .j a v  a2  s .c om*/
 * 
 * @param token
 * @return
 */
@SuppressLint("DefaultLocale")
private static boolean isMultiPartSeries(String token) {
    String re1 = "(PART)"; // Word 1
    String re2 = "( )"; // White Space 1
    String re3 = "(\\d+)"; // Integer Number 1

    Pattern p = Pattern.compile(re1 + re2 + re3, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
    Matcher m = p.matcher(token.toUpperCase());

    return m.find();
}

From source file:Main.java

public static String getYoutubeVideoId(String youtubeUrl) {
    String video_id = "";
    if (youtubeUrl != null && youtubeUrl.trim().length() > 0 && youtubeUrl.startsWith("http")) {

        String expression = "^.*((youtu.be" + "\\/)"
                + "|(v\\/)|(\\/u\\/w\\/)|(embed\\/)|(watch\\?))\\??v?=?([^#\\&\\?]*).*"; // var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
        CharSequence input = youtubeUrl;
        Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(input);
        if (matcher.matches()) {
            String groupIndex1 = matcher.group(7);
            if (groupIndex1 != null && groupIndex1.length() == 11)
                video_id = groupIndex1;/*from   w ww.  ja v a2 s  . c  o m*/
        }
    }
    return video_id;
}

From source file:Main.java

private static boolean matches(String[] filters, Matcher matcher) {
    for (String filter : filters) {
        // Is logcat filter?
        if (filter.matches("(\\w+|\\*):[\\w|\\*]")) {
            String[] matches = filter.split(":");
            // Tag and level match?
            if ((matches[0].equals("*") || matches[0].equals(matcher.group(6)))
                    && (matches[1].equals("*") || matches[1].equals(matcher.group(5)))) {
                return true;
            }//from   ww w.j  a va2  s. c  om
        } else {
            Pattern pattern = Pattern.compile(".*" + Pattern.quote(filter) + ".*", Pattern.CASE_INSENSITIVE);
            for (int i = 1; i < 8; i++) {
                if (pattern.matcher(matcher.group(i)).matches()) {
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:Main.java

/**
 * toSpannableString//  www  .j a v  a 2s .  c o  m
 * @return SpannableString
 * @throws
 */
public static SpannableString toSpannableString(Context context, String text) {
    if (!TextUtils.isEmpty(text)) {
        SpannableString spannableString = new SpannableString(text);
        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();
            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);
        }

        return spannableString;
    } else {
        return new SpannableString("");
    }
}

From source file:Main.java

public static String smartMediaName(String fileName) {
    String reg = "WinG|ENG|aAf|3D|720P|720p|1080P|1080p|X264|DTS|BluRay|Bluray|HSBS|x264|CHD|H-SBS|"
            + "Wiki|WiKi|ML|RemuX|CnSCG|HDChina|Sample|sample|AVC|MA|5.1|AC3|AAC|rip|265|"
            + "HDTV|DL|DHD|HD|HEVC|DiCH|dich|dhd|hdtv|Pix|BAWLS|hv|NG";
    //reduce ext//from   w  w w  .  ja v a  2 s . com
    String result = fileName.substring(0, fileName.lastIndexOf("."));
    //reduce other word like 720P,DTS,X264..
    result = result.replaceAll(reg, "");
    //reduce last .
    String endReg = "[0-9]|[|]|.| |-";
    String endX = "0123456789.-[] ";
    Pattern pattern = Pattern.compile(endReg, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(result);
    if (matcher.matches()) {
        return result;
    }
    if (result.length() > 2) {
        String endChar = result.substring(result.length() - 1, result.length());
        while (endX.contains(endChar)) {
            result = result.substring(0, result.length() - 1);
            if (result.length() > 2) {
                endChar = result.substring(result.length() - 1, result.length());
            } else {
                break;
            }
        }
    }
    return result;
}

From source file:Main.java

/**
 * Validates an email based on regex -/*from ww w  . ja  v a 2 s  . com*/
 * "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" +
 * "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
 * 
 * @param email
 *            String containing email address
 * @return True if the email is valid; false otherwise.
 */
public static boolean isEmailValid(String email) {
    boolean isValid = false;
    try {
        // Initialize reg ex for email.
        String expression = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
                + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
        CharSequence inputStr = email;
        // Make the comparison case-insensitive.
        Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(inputStr);
        if (matcher.matches()) {
            isValid = true;
        }
    } catch (NullPointerException e) {
        e.printStackTrace();
    }

    return isValid;
}

From source file:Main.java

public static final String replaceRegexAll(String fileContent, String from, String to, boolean isRegex,
        boolean caseSensitive) {
    if (!isRegex) {
        Log.d(from, to);/* www  . ja  v  a2s.co  m*/
        from = from.replaceAll(SPECIAL_CHAR_PATTERNSTR, "\\\\$1");
        to = to.replaceAll(SPECIAL_CHAR_PATTERNSTR, "\\\\$1");
        Log.d(from, to);
    }
    //System.out.println(fileContent);
    Pattern p = null;
    if (!caseSensitive) {
        p = Pattern.compile(from, Pattern.CASE_INSENSITIVE);
        //fileContent = fileContent.replaceAll("(?i)"+from, to);
    } else {
        p = Pattern.compile(from, Pattern.UNICODE_CASE);
        //fileContent = fileContent.replaceAll(from, to);
    }
    fileContent = p.matcher(fileContent).replaceAll(to);
    //System.out.println(fileContent);
    return fileContent;
}

From source file:Main.java

/**
 * Pattern.pattern and Pattern.toString ignore any flags supplied to
 * Pattern.compile, so the regular expression you get out doesn't
 * correspond to what the Pattern was actually matching. This fixes that.
 * /*from  w ww  . jav  a 2s .  c om*/
 * Note that there are some flags that can't be represented.
 * 
 * FIXME: why don't we use Pattern.LITERAL instead of home-grown escaping
 * code? Is it because you can't do the reverse transformation? Should we
 * integrate that code with this?
 */
public static String toString(Pattern pattern) {
    String regex = pattern.pattern();
    final int flags = pattern.flags();
    if (flags != 0) {
        StringBuilder builder = new StringBuilder("(?");
        toStringHelper(builder, flags, Pattern.UNIX_LINES, 'd');
        toStringHelper(builder, flags, Pattern.CASE_INSENSITIVE, 'i');
        toStringHelper(builder, flags, Pattern.COMMENTS, 'x');
        toStringHelper(builder, flags, Pattern.MULTILINE, 'm');
        toStringHelper(builder, flags, Pattern.DOTALL, 's');
        toStringHelper(builder, flags, Pattern.UNICODE_CASE, 'u');
        builder.append(")");
        regex = builder.toString() + regex;
    }
    return regex;
}