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.apache.solr.kelvin.testcases.SimpleCondition.java

private boolean checkRegexp(String re, String lowerCase) {
    try {// www.j a va  2s  .co  m
        Pattern p = Pattern.compile(re, Pattern.CASE_INSENSITIVE);
        return p.matcher(lowerCase).find();
    } catch (Exception e) {

    }
    return false;
}

From source file:com.github.anba.es6draft.test262.Test262Web.java

@Before
public void setUp() throws Throwable {
    // Filter disabled tests
    assumeTrue("Test disabled", test.isEnabled());

    String fileContent = test.readFile();
    if (!isValidTestConfiguration()) {
        return;//from   w  w w . j av a  2 s .  co m
    }

    final String preamble;
    if (test.isRaw() || test.isModule()) {
        preamble = "";
        preambleLines = 0;
    } else if (isStrictTest) {
        preamble = "\"use strict\";\nvar strict_mode = true;\n";
        preambleLines = 2;
    } else {
        preamble = "//\"use strict\";\nvar strict_mode = false;\n";
        preambleLines = 2;
    }
    sourceCode = Strings.concat(preamble, fileContent);

    global = globals.newGlobal(new SystemConsole(), test);
    exceptionHandler.setExecutionContext(global.getRealm().defaultContext());

    if (!test.isNegative()) {
        errorHandler.match(StandardErrorHandler.defaultMatcher());
        exceptionHandler.match(ScriptExceptionHandler.defaultMatcher());
    } else {
        expected.expect(Matchers.either(StandardErrorHandler.defaultMatcher())
                .or(ScriptExceptionHandler.defaultMatcher()));
        String errorType = test.getErrorType();
        if (errorType != null) {
            expected.expect(hasErrorMessage(global.getRealm().defaultContext(),
                    matchesPattern(errorType, Pattern.CASE_INSENSITIVE)));
        }
    }

    // Load test includes
    for (String name : test.getIncludes()) {
        global.include(name);
    }

    if (test.isAsync()) {
        async = global.createGlobalProperties(new Test262Async(), Test262Async.class);
    }
}

From source file:de.uniwue.info6.misc.StringTools.java

/**
 *
 *
 * @return/*  ww w  .  ja v a2 s. com*/
 */
public static String stripHtmlTagsForScenario(String text) {
    if (text != null) {
        text = text.replaceAll("(?i)<script.*?</script>", "");
        text = text.replaceAll("(?i)<javascript.*?</javascript>", "");
        text = text.replaceAll("(?i)<style.*?</style>", "");

        String REGEX_FIELD = "<[^>]*>";
        Matcher matcher = Pattern.compile(REGEX_FIELD, Pattern.CASE_INSENSITIVE).matcher(text);
        while (matcher.find()) {
            String snippet = matcher.group();
            String snippetNoSpaces = snippet.toLowerCase().replaceAll("[\\s\"\'0-9]", "");

            if (!snippetNoSpaces.equals("<br>") && !snippetNoSpaces.equals("<br/>")
                    && !snippetNoSpaces.equals("</span>") && !snippetNoSpaces.equals("<span>")
                    && !snippetNoSpaces.equals("</font>") && !snippetNoSpaces.equals("<font>")) {

                if (snippetNoSpaces.startsWith("<span")) {
                    if (!snippetNoSpaces.equals("<spanstyle=font-style:italic;>")
                            && !snippetNoSpaces.equals("<spanstyle=text-decoration:underline;>")
                            && !snippetNoSpaces.equals("<spanstyle=text-decoration:line-through;>")
                            && !snippetNoSpaces.equals("<spanstyle=color:rgb(,,);>")
                            && !snippetNoSpaces.equals("<spanstyle=font-weight:bold;>")) {
                        text = text.replace(snippet, "<span>");
                    }
                } else if (snippetNoSpaces.startsWith("<font")) {
                    if (!snippetNoSpaces.equals("<fontsize=>")) {
                        text = text.replace(snippet, "<font>");
                    }
                } else {
                    text = text.replaceFirst(snippet, "");
                }
            }
        }
    }
    return text;
}

From source file:com.bazaarvoice.dropwizard.caching.CacheControlConfigurationItem.java

private static Predicate<String> groupNameMatcher(String name) {
    if (name.equals("*")) {
        return Predicates.alwaysTrue();
    }//ww w  .j  a va  2 s . co  m

    return regexMatcher(Pattern.compile("" + "^" + Joiner.on(".*")
            .join(FluentIterable.from(Splitter.on('*').split(name)).transform(new Function<String, Object>() {
                public Object apply(String input) {
                    return input.length() == 0 ? input : Pattern.quote(input);
                }
            })) + "$", Pattern.CASE_INSENSITIVE));
}

From source file:azkaban.project.ProjectManager.java

public List<Project> getProjectsByRegex(String regexPattern) {
    List<Project> allProjects = new ArrayList<Project>();
    Pattern pattern;//from  w  ww  .ja v a2s.  c  o m
    try {
        pattern = Pattern.compile(regexPattern, Pattern.CASE_INSENSITIVE);
    } catch (PatternSyntaxException e) {
        logger.error("Bad regex pattern " + regexPattern);
        return allProjects;
    }
    for (Project project : getProjects()) {
        if (pattern.matcher(project.getName()).find()) {
            allProjects.add(project);
        }
    }
    return allProjects;
}

From source file:de.mirkosertic.desktopsearch.SearchPhraseSuggester.java

private String highlight(String aPhrase, List<String> aTokens) {
    String theResult = aPhrase;/*from  w  w w.j  ava2 s.  c  om*/
    Set<String> theTokens = aTokens.stream().map(String::toLowerCase).collect(Collectors.toSet());

    for (String theToken : theTokens) {
        Pattern thePattern = Pattern.compile("(" + theToken + ")", Pattern.CASE_INSENSITIVE);
        Matcher theMatcher = thePattern.matcher(aPhrase);
        Set<String> theReplacements = new HashSet<>();
        while (theMatcher.find()) {
            theReplacements.add(theMatcher.group());
        }
        for (String theReplacement : theReplacements) {
            theResult = theResult.replace(theReplacement, "<b>" + theReplacement + "</b>");
        }
    }
    return theResult;
}

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

/**
 * Verifies a potential GPG Fingerprint for a channel
 * @param gpgFp the gpg fingerprint of the channel
 * @return true if it is correct, false otherwise
 */// www .  j  a  va 2  s  .c  o m
public static boolean verifyGpgFingerprint(String gpgFp) {
    Pattern pattern = Pattern.compile("^(\\s*[0-9A-F]{4}\\s*){10}$", Pattern.CASE_INSENSITIVE);
    Matcher match = pattern.matcher(gpgFp);
    return match.matches();
}

From source file:net.darkmist.clf.Main.java

private void implMain(String args[]) throws IOException {
    PrintWriter out;//from   w w w  .  j  av  a  2s .  co  m
    LogHandler printer;
    String usrRegex;
    String usrLineRegex;
    String outFile;
    //MergingBatchHandler batchMerger;
    SortingBatchCombiner batchMerger;

    if (args.length < 3)
        usage("Insufficient arguments");
    usr = args[0];
    outFile = args[1];

    // get and fixup regex
    usrRegex = usr;
    if (!usrRegex.startsWith(".*") && !usrRegex.startsWith("^"))
        usrRegex = ".*" + usrRegex;
    if (!usrRegex.endsWith(".*") && !usrRegex.endsWith("$"))
        usrRegex = usrRegex + ".*";
    usrPattern = Pattern.compile(usrRegex, Pattern.CASE_INSENSITIVE);

    usrLineRegex = "^[^ ]+ [^ ]+ [^ ]*" + usr + "[^ ]* .*";
    if (logger.isDebugEnabled())
        logger.debug("usrLineRegex=" + usrLineRegex + '=');
    usrLinePattern = Pattern.compile(usrLineRegex, Pattern.CASE_INSENSITIVE);

    if (outFile.equals("-"))
        out = new PrintWriter(System.out);
    else
        out = new PrintWriter(outFile);

    printer = new PrintingLogHandler(out);
    //batchMerger = new MergingBatchHandler(new Batch2Entries(printer), LogEntry.getDateOnlyComparator());
    batchMerger = new SortingBatchCombiner(new Batch2Entries(printer), LogEntry.getDateOnlyComparator());
    chainDest = LogBatchHandler.Utils.synchronizedLogBatchHandler(batchMerger);

    // figure the input and let it rip
    handleFiles(args, 2, args.length - 2);
    logger.debug("handleFiles is done...");

    // Nothing is output until here!
    logger.debug("flusing batchMerger...");
    batchMerger.flush();
    logger.debug("flusing out...");
    out.flush();
    logger.debug("done");
}

From source file:com.log4ic.compressor.utils.HttpUtils.java

/**
 * ??//ww w .j a v a  2  s.c o  m
 *
 * @param str
 * @param regex
 * @return
 */
private static String findPattern(String str, String regex) {
    Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
    if (StringUtils.isEmpty(str)) {
        return null;
    }
    Matcher matcher = pattern.matcher(str);
    if (matcher.find()) {
        return matcher.group();
    }
    return null;
}

From source file:de.mpg.mpdl.inge.exportmanager.Export.java

public String explainFormatsXML() throws ExportManagerException {

    // TODO: Revision with ValueObjects

    String citStyles;// www .  java2s.  com
    try {
        citStyles = getCitationStyleHandler().explainStyles();
    } catch (Exception e) {
        throw new ExportManagerException("Cannot get citation styles explain", e);
    }

    String structured;
    try {
        structured = getStructuredExportHandler().explainFormats();
    } catch (Exception e) {
        throw new ExportManagerException("Cannot get structured exports explain", e);
    }

    String result;
    // get export-format elements
    String regexp = "<export-formats.*?>(.*?)</export-formats>";
    Matcher m = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(citStyles);
    m.find();
    result = m.group(1);
    m = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(structured);
    m.find();
    result += m.group(1);

    m = Pattern.compile("<export-format\\s+.*</export-format>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL)
            .matcher(structured);
    m.find();
    result = m.replaceAll(result);

    // replace comments
    // m = Pattern
    // .compile(
    // "<!--.*?-->"
    // , Pattern.CASE_INSENSITIVE | Pattern.DOTALL
    // )
    // .matcher(result);
    // m.find();
    // result = m.replaceAll("");

    return result;
}