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:com.redhat.rhn.domain.kickstart.builder.KickstartBuilder.java

/**
 * Tests to see if a kickstart label is valid or not
 * @param ksLabel The label to test/*  www .j a v a 2  s  .c o  m*/
 * @return true if it is valid, false otherwise
 */
private boolean isLabelValid(String ksLabel) {
    if (ksLabel.length() < MIN_KS_LABEL_LENGTH) {
        return false;
    }
    Pattern pattern = Pattern.compile("[A-Za-z0-9_-]+", Pattern.CASE_INSENSITIVE);
    Matcher match = pattern.matcher(ksLabel);
    return match.matches();
}

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

/**
 * URL?/*  ww w.  j a v a  2 s  .co  m*/
 *
 * @param code
 * @param fileUrl
 * @param type
 * @param fileDomain
 * @return
 */
public static String fixUrlPath(HttpServletRequest req, String code, String fileUrl, FileType type,
        String fileDomain) {

    StringBuilder codeBuffer = new StringBuilder();
    switch (type) {
    case GSS:
    case CSS:
    case LESS:
    case MSS:
        logger.debug("URL?...");
        Pattern pattern = Pattern.compile("url\\(\\s*(?!['\"]?(?:data:|about:|#|@))([^)]+)\\)",
                Pattern.CASE_INSENSITIVE);

        Matcher matcher = pattern.matcher(code);

        String[] codeFragments = pattern.split(code);

        fileUrl = fileUrl.substring(0, fileUrl.lastIndexOf("/") + 1);

        int i = 0;
        while (matcher.find()) {
            codeBuffer.append(codeFragments[i]);
            codeBuffer.append("url(");
            MatchResult result = matcher.toMatchResult();
            String url = result.group(1).replaceAll("'|\"", "");
            //???
            if (!HttpUtils.isHttpProtocol(url) && !url.startsWith("/")) {
                url = URI.create(fileUrl + url).normalize().toASCIIString();//?URL
            }

            //??url?http?)??????
            if (StringUtils.isNotBlank(fileDomain) && !HttpUtils.isHttpProtocol(url)) {
                if (!fileDomain.endsWith("/") && !url.startsWith("/")) {
                    fileDomain = fileDomain + "/";
                } else if (fileDomain.endsWith("/") && url.startsWith("/")) {
                    url = url.substring(1);
                }
                if (!HttpUtils.isHttpProtocol(fileDomain)) {
                    fileDomain = "http://" + fileDomain;
                }
                url = fileDomain + url;
            } else {
                url = req.getContextPath() + (url.startsWith("/") ? url : "/" + url);
            }
            codeBuffer.append(url);
            codeBuffer.append(")");
            i++;
        }
        if (i == 0) {
            return code;
        } else {
            if (codeFragments.length > i && StringUtils.isNotBlank(codeFragments[i])) {
                codeBuffer.append(codeFragments[i]);
            }
        }
        logger.debug("URL?...");
        break;
    default:
        return code;
    }
    return codeBuffer.toString();
}

From source file:databaseadapter.GenerateMojo.java

private boolean isToExclude(String table) {
    if (excludes == null || excludes.length == 0)
        return false;

    for (String regex : excludes) {
        getLog().debug("... checking table '" + table + "' against regex '" + regex
                + "' in order to check if it is to be excluded...");

        Matcher matcher = Pattern.compile(regex, Pattern.CASE_INSENSITIVE).matcher(table);
        if (matcher.matches())
            return true;
    }/*from   w w w .  ja v  a 2s  .c  o  m*/

    return false;
}

From source file:gate.creole.kea.CorpusImporter.java

protected boolean annotateKeyPhrases(Document document, String annSetName, String keyphraseAnnotationType,
        List<String> phrases) throws Exception {
    if (phrases == null || phrases.isEmpty())
        return false;
    //create a pattern
    String patternStr = "";
    Iterator<String> phraseIter = phrases.iterator();
    while (phraseIter.hasNext()) {
        String phrase = phraseIter.next();
        patternStr += patternStr.length() == 0 ? "\\Q" + phrase + "\\E" : "|\\Q" + phrase + "\\E";
    }/*from w  w w . j a v a  2s  . c o  m*/

    Pattern pattern = Pattern.compile(patternStr, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);

    Matcher matcher = pattern.matcher(document.getContent().toString());
    AnnotationSet outputSet = annSetName == null || annSetName.length() == 0 ? document.getAnnotations()
            : document.getAnnotations(annSetName);
    boolean result = false;
    while (matcher.find()) {
        int start = matcher.start();
        int end = matcher.end();
        outputSet.add(new Long(start), new Long(end), keyphraseAnnotationType, Factory.newFeatureMap());
        result = true;
    }
    document.getFeatures().put("Author assigned keyphrases", phrases);
    return result;
}

From source file:gtu.log.finder.ExceptionLogFinderUI.java

private void searchTextBtnAction() {
    File parseFile = getParseFile();
    if (outputLogFile == null || !outputLogFile.exists()) {
        if (parseFile != null) {
            outputLogFile = parseFile;/*from  w  ww.j a v  a 2 s  .c  o m*/
        } else {
            JCommonUtil._jOptionPane_showMessageDialog_error("??");
            return;
        }
    }
    String searchTxt = searchText.getText();
    System.out.println("findText ==> " + searchTxt);
    try {
        Pattern startPtn = Pattern.compile("?(\\d+)[]+");
        Pattern searchTextPtn = Pattern.compile(searchTxt, Pattern.CASE_INSENSITIVE);
        if (!ignoreCaseCheckBox.isSelected()) {
            searchTextPtn = Pattern.compile(searchTxt);
        }

        List<ExceptionSection> exceptionSecList = new ArrayList<ExceptionSection>();
        String tempSecStr = null;
        Matcher matcher = null;
        List<String> markLineSectionNumberList = new ArrayList<String>();
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(new FileInputStream(outputLogFile), "utf8"));
        for (String line = null; (line = reader.readLine()) != null;) {
            matcher = startPtn.matcher(line);
            if (matcher.find()) {
                tempSecStr = matcher.group(1);
            }
            if (tempSecStr == null) {
                continue;
            }
            String tmpLine = line.replaceFirst("[\\d]+\\:", "");
            tmpLine = tmpLine.replaceFirst("\\([\\d]+\\)\\:", "");
            if (tmpLine.contains(searchTxt) || searchTextPtn.matcher(tmpLine).find()) {
                System.out.println("\ttempSecStr => " + tempSecStr);
                System.out.println("\ttmpLine => " + tmpLine);
                if (!markLineSectionNumberList.contains(tempSecStr)) {
                    ExceptionSection es = new ExceptionSection();
                    es.line = line;
                    es.sectionNumber = Integer.parseInt(tempSecStr);
                    exceptionSecList.add(es);
                    System.out.println(es);
                    markLineSectionNumberList.add(tempSecStr);
                    tempSecStr = null;
                }
            } else {
                System.out.println(":" + tmpLine);
            }
        }
        reader.close();

        DefaultListModel searchMatchListModel = new DefaultListModel();
        for (int ii = 0; ii < exceptionSecList.size(); ii++) {
            ExceptionSection es = exceptionSecList.get(ii);
            searchMatchListModel.addElement(es);
        }
        searchMatchList.setModel(searchMatchListModel);
        if (exceptionSecList.isEmpty()) {
            JCommonUtil._jOptionPane_showMessageDialog_info("??!");
        }
    } catch (Exception ex) {
        JCommonUtil.handleException(ex);
    }
}

From source file:de.javakaffee.kryoserializers.KryoTest.java

@Test(enabled = true)
public void testCopyRegex() throws Exception {
    final Holder<Pattern> pattern = new Holder<Pattern>(Pattern.compile("regex"));
    final Holder<Pattern> copy = _kryo.copy(pattern);
    assertDeepEquals(copy, pattern);/*  w w  w  .  ja  v a 2s  . com*/

    final Holder<Pattern> patternWithFlags = new Holder<Pattern>(
            Pattern.compile("\n", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE));
    final Holder<Pattern> copyWithFlags = _kryo.copy(patternWithFlags);
    assertDeepEquals(copyWithFlags, patternWithFlags);
}

From source file:esg.node.components.monitoring.MonitorDAO.java

private void loadCPUInfoResource() {
    cpuInfoResource = new InfoResources("/proc/cpuinfo",
            Integer.parseInt(props.getProperty("monitor.buffer.cpuinfo", "-1")));
    cpuInfoPattern = Pattern.compile("cpu MHz\\s*:\\s*(\\d+\\.\\d*)", Pattern.CASE_INSENSITIVE);
}

From source file:org.ednovo.gooru.application.util.ResourceImageUtil.java

public static String getYoutubeVideoId(String url) {
    String pattern = "youtu(?:\\.be|be\\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]{11}+)";
    String videoId = null;/* ww  w .  ja  va2  s .  c  o m*/
    Pattern compiledPattern = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
    Matcher matcher = compiledPattern.matcher(url);
    if (matcher != null) {
        while (matcher.find()) {
            videoId = matcher.group(1);
        }
    }
    return videoId;
}

From source file:de.undercouch.bson4jackson.BsonParser.java

/**
 * Converts a BSON regex pattern string to a combined value of Java flags that
 * can be used in {@link Pattern#compile(String, int)}
 * @param pattern the regex pattern string
 * @return the Java flags/*from  w  ww .j  a  v a2 s .  c o m*/
 * @throws JsonParseException if the pattern string contains a unsupported flag
 */
protected int regexStrToFlags(String pattern) throws JsonParseException {
    int flags = 0;
    for (int i = 0; i < pattern.length(); ++i) {
        char c = pattern.charAt(i);
        switch (c) {
        case 'i':
            flags |= Pattern.CASE_INSENSITIVE;
            break;

        case 'm':
            flags |= Pattern.MULTILINE;
            break;

        case 's':
            flags |= Pattern.DOTALL;
            break;

        case 'u':
            flags |= Pattern.UNICODE_CASE;
            break;

        case 'l':
        case 'x':
            //unsupported
            break;

        default:
            throw new JsonParseException("Invalid regex", getTokenLocation());
        }
    }
    return flags;
}