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:org.jahia.modules.irclogs.eggdrop.EggChatlogChannel.java

/**
 * This function replaces links and make the output html 'save'
 *
 * TODO: Make this more universal, possibly in a top level class somehow, or as a taglib?
 *
 * @param line/*from  w w  w .  j  a v a 2s  .  co  m*/
 * @return
 */
private String defaultLineReplacements(String line) {
    final Pattern userPattern = Pattern.compile("Users/\\S+/?\\S*", Pattern.CASE_INSENSITIVE);
    final Pattern homePattern = Pattern.compile("Home/\\S+/?\\S*", Pattern.CASE_INSENSITIVE);
    final Pattern emailPattern = Pattern.compile(
            "([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})",
            Pattern.CASE_INSENSITIVE);
    final Pattern urlPattern = Pattern.compile("(\\A|\\s)((http|https|ftp):\\S+)(\\s|\\z)",
            Pattern.CASE_INSENSITIVE);

    line = userPattern.matcher(line).replaceAll("Users/<removed>/...");
    line = homePattern.matcher(line).replaceAll("Home/<removed>/...");
    line = emailPattern.matcher(line).replaceAll("(obscured mail address)");

    line = StringUtils.replaceEach(line, new String[] { "&", "\"", "<", ">", "#" },
            new String[] { "&amp;", "&quot;", "&lt;", "&gt;", "&#35;" });

    line = urlPattern.matcher(line).replaceAll("$1<a target=\"_blank\" href=\"$2\">$2</a>$4");
    return line;
}

From source file:com.nextep.designer.sqlgen.helpers.CaptureHelper.java

private static String getBodyFromCreateAsStatement(String stmt, String bodyStartKeyword) {
    String body = null;// www  . j  a  v  a 2 s.c  o  m
    if (stmt != null) {
        /*
         * FIXME [BGA] This expression will not work for bodies that start with a DECLARE
         * keyword. The expression should not rely on the first keyword of the body section, as
         * this first keyword can vary, but should instead rely on the previous AS keyword which
         * is always the same.
         */
        Pattern p = Pattern.compile("^.+?\\s+AS\\s+(" + bodyStartKeyword + "\\s+.+)", //$NON-NLS-1$ //$NON-NLS-2$
                Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
        Matcher m = p.matcher(stmt);
        if (m.find()) {
            try {
                body = m.group(1);
                if (body != null && !"".equals(body.trim())) { //$NON-NLS-1$
                    return body;
                }
            } catch (IllegalStateException ise) {
                LOGGER.warn(bodyStartKeyword
                        + " keyword could not be found in the specified CREATE AS statement [" + stmt + "]", //$NON-NLS-2$
                        ise);
            }
        }
    }
    if (body == null || "".equals(body.trim())) { //$NON-NLS-1$
        // If we failed extracting the BODY clause, we simply try to return the passed statement
        // as this is better than nothing. (Attempt to fix DES-927)
        return stmt;
    } else {
        return body;
    }
}

From source file:com.sangupta.pep.Generator.java

private SlideVariables getSlideVariables(String slideContents) {
    SlideVariables vars = new SlideVariables();

    Matcher matcher = PATTERN.matcher(slideContents);

    if (matcher != null && matcher.matches()) {
        vars.setHeader(matcher.group(1));
        vars.setLevel(Integer.valueOf(matcher.group(2)));
        vars.setTitle(matcher.group(3));
        vars.setContent(matcher.group(4));
    } else {//from   w w w.  ja  va 2  s .  com
        vars.setHeader("");
        vars.setTitle("");
        vars.setContent(slideContents);
        vars.setLevel(0);
    }

    // process slide classes
    ContentAndClasses cc = processMacros(vars);

    String content = cc.getContent();
    vars.setContent(content);
    vars.setClasses(cc.getClasses().toArray(new String[0]));

    if (StringUtils.isNotEmpty(content)) {
        content = content.trim();
        Pattern p2 = Pattern.compile("<h\\d[^>]*>presenter notes</h\\d>",
                Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL);
        Matcher m2 = p2.matcher(content);

        if (m2 != null && m2.matches()) {
            vars.setPresenterNotes(content.substring(m2.end()).trim());
            content = content.substring(0, m2.start());

            vars.setContent(content);
        }
    }

    vars.setRelativeSourcePath(this.inputFile.getPath());
    vars.setAbsoluteSourcePath(this.inputFile.getAbsolutePath());

    return vars;
}

From source file:com.redhat.rhn.domain.channel.NewChannelHelper.java

/**
 * Verifies a potential GPG URL for a channel
 * @param gpgUrl the gpg url of the channel
 * @return true if it is correct, false otherwise
 *//*  ww  w.  j  av  a 2s.  c  o m*/
public static boolean verifyGpgUrl(String gpgUrl) {
    Pattern pattern = Pattern.compile("^(http[s]*|file)?\\://.*?$", Pattern.CASE_INSENSITIVE);
    Matcher match = pattern.matcher(gpgUrl);
    return match.matches();
}

From source file:com.ibuildapp.romanblack.TableReservationPlugin.TableReservationEMailSignUpActivity.java

/**
 * Validates values of input fields.//from   ww w  .j  a  v a 2 s .  c o m
 */
private void checkFields() {
    if (!needCheckFields) {
        return;
    }

    if ((firstNameEditText.getText().toString().length() > 0)
            && (lastNameEditText.getText().toString().length() > 0)
            && (emailEditText.getText().toString().length() > 0)
            && (passwordEditText.getText().toString().length() > 0)
            && (rePasswordEditText.getText().toString().length() > 0)) {
        String regExpn = "^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]{1}|[\\w-]{2,}))@"
                + "((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?" + "[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\."
                + "([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?" + "[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
                + "([a-zA-Z]+[\\w-]+\\.)+[a-zA-Z]{2,4})$";

        Pattern pattern = Pattern.compile(regExpn, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(emailEditText.getText().toString());

        if (matcher.matches()) {
        } else {
            signUpActive = false;
            return;
        }

        if (!firstNameEditText.getText().toString().equals(lastNameEditText.getText().toString())) {
        } else {
            signUpActive = false;
            return;
        }

        if (passwordEditText.getText().toString().equals(rePasswordEditText.getText().toString())) {
        } else {
            signUpActive = false;
            return;
        }

        if (passwordEditText.getText().toString().length() >= 4) {
        } else {
            signUpActive = false;
            return;
        }

        signUpActive = true;

    } else {
        signUpActive = false;
    }
}

From source file:net.longfalcon.newsj.CategoryService.java

public int determineCategory(long groupId, final String releaseName) {
    tmpCat = 0;//from   www  . ja v a  2  s .c om
    long startTime = System.currentTimeMillis();
    Group group = groupDAO.findGroupByGroupId(groupId);
    String groupName = group.getName();
    //
    // Try and determine based on group - First Pass
    //
    Pattern pattern = Pattern.compile("alt\\.binaries\\.ath", Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isConsole(releaseName)) {
            return tmpCat;
        }
        if (isPC(releaseName)) {
            return tmpCat;
        }
        if (isMovie(releaseName)) {
            return tmpCat;
        }
        if (isMusic(releaseName)) {
            return tmpCat;
        }
    }

    pattern = Pattern.compile("alt\\.binaries\\.b4e", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isPC(releaseName)) {
            return tmpCat;
        }
        if (isEBook(releaseName)) {
            return tmpCat;
        }
    }

    pattern = Pattern.compile("anime", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find())
        return CAT_MISC_ANIME;

    pattern = Pattern.compile("alt\\.binaries\\..*?audiobook\\.*?", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find())
        return CAT_MUSIC_AUDIOBOOK;

    pattern = Pattern.compile("lossless|flac", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        return CAT_MUSIC_LOSSLESS;
    }

    pattern = Pattern.compile("alt\\.binaries\\.sounds.*?|alt\\.binaries\\.mp3.*?|alt\\.binaries\\..*\\.mp3",
            Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isMusic(releaseName)) {
            return tmpCat;
        }
        return CAT_MUSIC_MP3;
    }

    pattern = Pattern.compile("alt\\.binaries\\.console\\.ps3", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find())
        return CAT_GAME_PS3;

    pattern = Pattern.compile("alt\\.binaries\\.games\\.xbox*", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isConsole(releaseName)) {
            return tmpCat;
        }
        if (isTV(releaseName)) {
            return tmpCat;
        }
        if (isMovie(releaseName)) {
            return tmpCat;
        }
    }

    pattern = Pattern.compile("alt\\.binaries\\.games", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isConsole(releaseName)) {
            return tmpCat;
        }
        return CAT_PC_GAMES;
    }

    pattern = Pattern.compile("alt\\.binaries\\.games\\.wii", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isConsole(releaseName)) {
            return tmpCat;
        }
        return CAT_GAME_WII;
    }

    pattern = Pattern.compile("alt\\.binaries\\.dvd.*?", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isXxx(releaseName)) {
            return tmpCat;
        }
        if (isTV(releaseName)) {
            return tmpCat;
        }
        if (isMovie(releaseName)) {
            return tmpCat;
        }
    }

    pattern = Pattern.compile("alt\\.binaries\\.hdtv*|alt\\.binaries\\.x264", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isXxx(releaseName)) {
            return tmpCat;
        }
        if (isTV(releaseName)) {
            return tmpCat;
        }
        if (isMovie(releaseName)) {
            return tmpCat;
        }
    }

    pattern = Pattern.compile("alt\\.binaries\\.classic\\.tv.*?", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        return CAT_TV_SD;
    }

    pattern = Pattern.compile("alt\\.binaries\\.e-book*?", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        return CAT_MISC_EBOOK;
    }

    pattern = Pattern.compile("alt\\.binaries\\.comics.*?", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        return CAT_MISC_COMICS;
    }

    pattern = Pattern.compile("alt\\.binaries\\.cores.*?", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isXxx(releaseName)) {
            return tmpCat;
        }
        if (isMovie(releaseName)) {
            return tmpCat;
        }
        if (isConsole(releaseName)) {
            return tmpCat;
        }
        if (isPC(releaseName)) {
            return tmpCat;
        }
    }

    pattern = Pattern.compile("alt\\.binaries\\.cd.image|alt\\.binaries\\.audio\\.warez",
            Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isPC(releaseName)) {
            return tmpCat;
        }
        return CAT_PC_0DAY;
    }

    pattern = Pattern.compile("alt\\.binaries\\.sony\\.psp", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find())
        return CAT_GAME_PSP;

    pattern = Pattern.compile("alt\\.binaries\\.nintendo\\.ds|alt\\.binaries\\.games\\.nintendods",
            Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        return CAT_GAME_NDS;
    }

    pattern = Pattern.compile("alt\\.binaries\\.mpeg\\.video\\.music", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        return CAT_MUSIC_VIDEO;
    }

    pattern = Pattern.compile("alt\\.binaries\\.mac", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        return CAT_PC_MAC;
    }

    pattern = Pattern.compile("linux", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        return CAT_PC_ISO;
    }

    pattern = Pattern.compile("alt\\.binaries\\.ipod\\.videos\\.tvshows", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find())
        return CAT_TV_OTHER;

    pattern = Pattern.compile("alt\\.binaries\\.documentaries", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isXxx(releaseName)) {
            return tmpCat;
        }
        if (isTV(releaseName)) {
            return tmpCat;
        }
        return CAT_TV_SD;
    }

    pattern = Pattern.compile("alt\\.binaries\\.tv\\.swedish", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        return CAT_TV_FOREIGN;
    }

    pattern = Pattern.compile("alt\\.binaries\\.erotica\\.divx", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        return CAT_XXX_XVID;
    }

    pattern = Pattern.compile("alt\\.binaries\\.mma|alt\\.binaries\\.multimedia\\.sports.*?",
            Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        return CAT_TV_SPORT;
    }

    pattern = Pattern.compile("alt\\.binaries\\.b4e$", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isPC(releaseName)) {
            return tmpCat;
        }
    }

    pattern = Pattern.compile("alt\\.binaries\\.warez\\.smartphone", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find())
        if (isPC(releaseName)) {
            return tmpCat;
        }

    pattern = Pattern.compile("alt\\.binaries\\.warez\\.ibm\\-pc\\.0\\-day|alt\\.binaries\\.warez",
            Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isConsole(releaseName)) {
            return tmpCat;
        }
        if (isEBook(releaseName)) {
            return tmpCat;
        }
        if (isXxx(releaseName)) {
            return tmpCat;
        }
        if (isPC(releaseName)) {
            return tmpCat;
        }
        if (isTV(releaseName)) {
            return tmpCat;
        }
        return CAT_PC_0DAY;
    }

    pattern = Pattern.compile("alt\\.binaries\\.(teevee|multimedia|tv|tvseries)", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isXxx(releaseName)) {
            return tmpCat;
        }
        if (isTV(releaseName)) {
            return tmpCat;
        }
        if (isForeignTV(releaseName)) {
            return tmpCat;
        }
        return CAT_TV_OTHER;
    }

    pattern = Pattern.compile("erotica", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isXxx(releaseName)) {
            return tmpCat;
        }
        return CAT_XXX_XVID;
    }

    pattern = Pattern.compile(
            "alt\\.binaries\\.movies\\.xvid|alt\\.binaries\\.movies\\.divx|alt\\.binaries\\.movies",
            Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isConsole(releaseName)) {
            return tmpCat;
        }
        if (isXxx(releaseName)) {
            return tmpCat;
        }
        if (isTV(releaseName)) {
            return tmpCat;
        }
        if (isMovie(releaseName)) {
            return tmpCat;
        }
        return CAT_MOVIE_SD;
    }

    pattern = Pattern.compile("wmvhd", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isXxx(releaseName)) {
            return tmpCat;
        }
        if (isTV(releaseName)) {
            return tmpCat;
        }
        if (isMovie(releaseName)) {
            return tmpCat;
        }
    }

    pattern = Pattern.compile("inner\\-sanctum", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isPC(releaseName)) {
            return tmpCat;
        }
        if (isEBook(releaseName)) {
            return tmpCat;
        }
        return CAT_MUSIC_MP3;
    }

    pattern = Pattern.compile("alt\\.binaries\\.x264", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(groupName);
    if (matcher.find()) {
        if (isXxx(releaseName)) {
            return tmpCat;
        }
        if (isTV(releaseName)) {
            return tmpCat;
        }
        if (isMovie(releaseName)) {
            return tmpCat;
        }
        return CAT_MOVIE_OTHER;
    }

    //
    // if a category hasnt been set yet, then try against all
    // functions and if still nothing, return Cat Misc.
    //
    if (isXxx(releaseName)) {
        return tmpCat;
    }
    if (isPC(releaseName)) {
        return tmpCat;
    }
    if (isTV(releaseName)) {
        return tmpCat;
    }
    if (isMovie(releaseName)) {
        return tmpCat;
    }
    if (isConsole(releaseName)) {
        return tmpCat;
    }
    if (isMusic(releaseName)) {
        return tmpCat;
    }
    if (isEBook(releaseName)) {
        return tmpCat;
    }

    Period determineCatTime = new Period(startTime, System.currentTimeMillis());
    _log.info("Determining category for " + releaseName + " took " + _periodFormatter.print(determineCatTime));

    return CAT_MISC;
}

From source file:net.bashtech.geobot.ReceiverBot.java

public ReceiverBot(String server, int port) {
    ReceiverBot.setInstance(this);

    linkPatterns[0] = Pattern.compile(".*http://.*", Pattern.CASE_INSENSITIVE);
    linkPatterns[1] = Pattern.compile(".*https://.*", Pattern.CASE_INSENSITIVE);
    linkPatterns[2] = Pattern.compile(
            ".*[-A-Za-z0-9]+\\s?(\\.|\\(dot\\))\\s?(ac|ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|as|asia|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir|is|it|je|jm|jo|jobs|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|post|pr|pro|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sx|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|travel|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|xxx|ye|yt|za|zm|zw)(\\W|$).*",
            Pattern.CASE_INSENSITIVE);
    linkPatterns[3] = Pattern.compile(
            ".*(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\s+|:|/|$).*");

    symbolsPatterns[0] = Pattern.compile(
            "(\\p{InPhonetic_Extensions}|\\p{InLetterlikeSymbols}|\\p{InDingbats}|\\p{InBoxDrawing}|\\p{InBlockElements}|\\p{InGeometricShapes}|\\p{InHalfwidth_and_Fullwidth_Forms}|||?????????|||||e|U||A|E)");
    symbolsPatterns[1] = Pattern.compile("[!-/:-@\\[-`{-~]");

    this.setName(BotManager.getInstance().nick);
    this.setLogin(this.getName());
    this.setMessageDelay(0);
    botName = this.getNick();
    this.setVerbose(BotManager.getInstance().verboseLogging);

    try {/*  w  w w  .  j  a  v a 2  s .c om*/
        this.connect(server, port, BotManager.getInstance().password);
    } catch (NickAlreadyInUseException e) {
        logMain("RB: [ERROR] Nickname already in use - " + this.getNick() + " " + this.getServer());
    } catch (IOException e) {
        logMain("RB: [ERROR] Unable to connect to server - " + this.getNick() + " " + this.getServer());
    } catch (IrcException e) {
        logMain("RB: [ERROR] Error connecting to server - " + this.getNick() + " " + this.getServer());
    }

}

From source file:com.bazaarvoice.seo.sdk.util.BVUtility.java

/**
 * Validates if the content has a valid bv content.
 * This is used to validate if the response is not corrupted.
 * @param content//from ww w .  j  a  v  a2  s.co m
 * @return
 */
public static boolean validateBVContent(String content) {
    if (BV_PATTERN == null) {
        BV_PATTERN = Pattern.compile(BVConstant.BV_STRING_PATTERN, Pattern.CASE_INSENSITIVE);
    }

    Matcher m = BV_PATTERN.matcher(content);
    return m.find();
}

From source file:csiro.pidsvc.mappingstore.Manager.java

protected void refreshCaseSensitivity() {
    String caseSensitive = getSetting("CaseSensitiveURI");
    _caseSensitivity.IsCaseSensitive = caseSensitive != null && caseSensitive.equalsIgnoreCase("1");
    _caseSensitivity.RegularExpressionFlags = _caseSensitivity.IsCaseSensitive ? 0 : Pattern.CASE_INSENSITIVE;
}

From source file:net.longfalcon.web.AdminRegexController.java

@RequestMapping("/admin/regex-test")
public String testRegexView(
        @RequestParam(value = "action", required = false, defaultValue = "view") String action,
        @RequestParam(value = "regex", required = false) String regex,
        @RequestParam(value = "groupId", required = false) Long groupId,
        @RequestParam(value = "groupName", required = false) String groupName,
        @RequestParam(value = "offset", required = false, defaultValue = "0") Integer offset,
        @RequestParam(defaultValue = "false") boolean unreleased, Model model) {
    title = "Release Regex Test";

    if (ValidatorUtil.isNull(regex)) {
        regex = "/^(?P<name>.*)$/i";
    }//w  ww  .j a  v  a 2s . c  o  m

    if (ValidatorUtil.isNull(groupId)) {
        groupId = -1L;
    }

    if (ValidatorUtil.isNotNull(groupName)) {
        Group group = groupDAO.getGroupByName(groupName);
        if (group != null) {
            groupId = group.getId();
        }
    }

    List<Group> groupList = groupDAO.getActiveGroups();
    List<Binary> matchesList = new ArrayList<>();
    Map<String, Binary> matchesMap = new HashMap<>();
    int pagerTotalItems = 0;

    if (ValidatorUtil.isNotNull(regex) && ValidatorUtil.isNotNull(groupId)) {
        String realRegex = fixRegex(regex);
        List<Integer> procstats = Arrays.asList(Defaults.PROCSTAT_NEW, Defaults.PROCSTAT_READYTORELEASE,
                Defaults.PROCSTAT_WRONGPARTS);
        if (unreleased) {
            matchesList = binaryDAO.findByGroupIdProcStatsReleaseId(groupId, procstats, null);
        } else {
            matchesList = binaryDAO.findByGroupIdProcStatsReleaseId(groupId, null, 0L);
        }

        for (Binary binary : matchesList) {
            Pattern pattern = Pattern.compile(fixRegex(regex), Pattern.CASE_INSENSITIVE); // remove '/' and '/i'
            String testMessage = "Test run - Binary Name " + binary.getName();

            Matcher groupRegexMatcher = pattern.matcher(binary.getName());
            if (groupRegexMatcher.find()) {
                String reqIdGroup = null;
                try {
                    reqIdGroup = groupRegexMatcher.group("reqid");
                } catch (IllegalArgumentException e) {
                    _log.debug(e.toString());
                }
                String partsGroup = null;
                try {
                    partsGroup = groupRegexMatcher.group("parts");
                } catch (IllegalArgumentException e) {
                    _log.debug(e.toString());
                }
                String nameGroup = null;
                try {
                    nameGroup = groupRegexMatcher.group("name");
                } catch (Exception e) {
                    _log.debug(e.toString());
                }
                _log.debug(testMessage + " matches with: \n reqId = " + reqIdGroup + " parts = " + partsGroup
                        + " and name = " + nameGroup);

                if ((ValidatorUtil.isNotNull(reqIdGroup) && ValidatorUtil.isNumeric(reqIdGroup))
                        && ValidatorUtil.isNull(nameGroup)) {
                    nameGroup = reqIdGroup;
                }

                if (ValidatorUtil.isNull(nameGroup)) {
                    _log.debug(String.format(
                            "regex applied which didnt return right number of capture groups - %s", regex));
                    _log.debug(String.format("regex matched: reqId = %s parts = %s and name = %s", reqIdGroup,
                            partsGroup, nameGroup));
                    continue;
                }

                int relTotalPart = 0;
                if (ValidatorUtil.isNotNull(partsGroup)) {
                    String partsStrings[] = partsGroup.split("/");
                    int relpart = Integer.parseInt(partsStrings[0]);
                    relTotalPart = Integer.parseInt(partsStrings[1]);
                }

                binary.setRelName(nameGroup);
                if (ValidatorUtil.isNotNull(reqIdGroup)) {
                    binary.setReqId(Integer.valueOf(reqIdGroup));
                }
                binary.setRelPart(relTotalPart);

                if (!matchesMap.containsKey(nameGroup)) {
                    binary.setRelTotalPart(1);
                    int categoryId = categoryService.determineCategory(groupId, nameGroup);
                    binary.setCategoryName(categoryService.getCategoryDisplayName(categoryId));
                    binary.setCategoryId(categoryId);
                    matchesMap.put(nameGroup, binary);
                } else {
                    Binary prevMatch = matchesMap.get(nameGroup);
                    int count = prevMatch.getRelTotalPart();
                    prevMatch.setRelTotalPart(count + 1);
                }
            }
        }
        List<Binary> valuesList = new ArrayList<>(matchesMap.values());
        pagerTotalItems = valuesList.size();
        matchesList = ArrayUtil.paginate(valuesList, offset, PAGE_SIZE);
    }

    model.addAttribute("title", title);
    model.addAttribute("regex", regex);
    model.addAttribute("groupId", groupId);
    model.addAttribute("groupList", groupList);
    model.addAttribute("unreleased", unreleased);
    model.addAttribute("matchesList", matchesList);
    model.addAttribute("pagerTotalItems", pagerTotalItems);
    model.addAttribute("pagerOffset", offset);
    model.addAttribute("pagerItemsPerPage", PAGE_SIZE);
    return "admin/regex-test";
}