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:apm.common.utils.StringUtils.java

public static String getClearWhereSQL(String table_sql_temp) {
    Pattern p = Pattern.compile("\\s*where\\s*1\\s*=\\s*1\\s*and?",
            Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    table_sql_temp = p.matcher(table_sql_temp).replaceAll(" _W_H_E_R_E_ ");
    p = Pattern.compile("\\s*where\\s*1\\s*=\\s*1\\s*", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    table_sql_temp = p.matcher(table_sql_temp).replaceAll(" ");
    p = Pattern.compile(" _W_H_E_R_E_ ", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    table_sql_temp = p.matcher(table_sql_temp).replaceAll(" WHERE ");
    return table_sql_temp;
}

From source file:de.unidue.inf.is.ezdl.gframedl.utils.HighlightingUtils.java

/**
 * Returns {@link Matcher} for highlighting.
 * //from  w  w w .j a  v a2s. c  om
 * @param highlightStrings
 * @param escapeHighlightStrings
 * @param stringToHighlight
 * @param highlightOnlyWords
 *            true, if only words should be highlighted
 * @return
 */
public static Matcher matcher(List<String> highlightStrings, boolean escapeHighlightStrings,
        String stringToHighlight, boolean highlightOnlyWords) {
    if (stringToHighlight == null || highlightStrings.isEmpty()
            || highlightStrings.size() == 1 && highlightStrings.get(0).isEmpty()) {
        return null;
    }

    String p = highlightOnlyWords ? "\\b(" : "(";
    for (int i = 0; i < highlightStrings.size(); i++) {
        String queryTerm = highlightStrings.get(i);
        if (escapeHighlightStrings) {
            p += Pattern.quote(queryTerm);
        } else {
            p += queryTerm;

        }
        if (i < highlightStrings.size() - 1) {
            p += "|";
        }
    }
    p += highlightOnlyWords ? ")\\b" : ")";
    Pattern pattern = Pattern.compile(p, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    Matcher matcher = pattern.matcher(stringToHighlight);
    return matcher;
}

From source file:org.ubicompforall.cityexplorer.gui.ImportWebTab.java

/***
 * Extract database URLs from the web-page source code, given as the string text
 * @param text   the web-page source code
 * @return      new web-page source code with multiple "<A HREF='databaseX.sqlite'>databaseX</A>" only
 *///from   w w w  .j a  v a 2s.  c  o m
public static CopyOnWriteArrayList<DB> extractDBs(String text, String SERVER_URL) {
    webDBs = new CopyOnWriteArrayList<DB>(); //To avoid duplicates!
    Matcher m = Pattern.compile("<a.* href=\"([^>]+(sqlite|db|db3))\">([^<]+)</a>", Pattern.CASE_INSENSITIVE)
            .matcher(text);
    while (m.find()) {
        String filename = m.group(1);
        if (filename.charAt(0) == '/') {
            filename = SERVER_URL + filename;
        }
        //webDBs.add( new DB(URL.getParentFile().getParent(), URL.getParentFile().getName(), URL.getName(), m.group(3) ) );
        // group 0 is everything, group 1 is (www.and.so.on)
        try {
            URL url = new URL(filename);
            File file = new File(filename);
            debug(1, "URL is  " + url);
            webDBs.add(new DB(file.getParentFile().getParent(), file.getParentFile().getName(), file.getName(),
                    url));
            debug(1, "Added: " + filename + " " + m.group(3));
        } catch (MalformedURLException e) {
            debug(-1, e.getMessage());
        }
    }
    return webDBs;
}

From source file:de.hybris.platform.order.strategies.paymentinfo.impl.DefaultCreditCardNumberHelper.java

private Pattern getOrCreateCachedCardPattern(final String key) {
    Pattern compiledPattern = null;
    if (patternCache.containsKey(key)) {
        compiledPattern = patternCache.get(key);
    } else {/*from  ww w  .  j  a va  2  s. co m*/
        synchronized (patternCache) {
            compiledPattern = Pattern.compile(key, Pattern.CASE_INSENSITIVE);
            patternCache.put(key, compiledPattern);
        }
    }
    return compiledPattern;
}

From source file:de.tbuchloh.kiskis.gui.common.Application.java

private static Program findProgram(final Preferences prefs, final String url) throws ProgramNotFoundException {
    final Program[] progs = initPrograms(prefs);
    for (final Program p : progs) {
        final Pattern pattern = Pattern.compile(p.getUrlRegex(), Pattern.CASE_INSENSITIVE);
        if (pattern.matcher(url).matches() || url.startsWith(p.getUrlRegex())) {
            return (Program) p.clone();
        }//from w  ww  .  j a v  a  2  s  .co  m
    }
    final String format = MessageFormat.format(MSG_NO_PROG_FOUND, new Object[] { url });
    throw new ProgramNotFoundException(format);
}

From source file:com.ikanow.aleph2.enrichment.utils.services.SimpleRegexFilterService.java

/**
 * Converts a string of regex flags into a single int representing those
 * flags for using in the java Pattern object
 * /*from ww  w  . jav a2  s  .  co  m*/
 * @param flagsStr
 * @return
 */
public static int parseFlags(final String flagsStr) {
    int flags = 0;
    for (int i = 0; i < flagsStr.length(); ++i) {
        switch (flagsStr.charAt(i)) {
        case 'i':
            flags |= Pattern.CASE_INSENSITIVE;
            break;
        case 'x':
            flags |= Pattern.COMMENTS;
            break;
        case 's':
            flags |= Pattern.DOTALL;
            break;
        case 'm':
            flags |= Pattern.MULTILINE;
            break;
        case 'u':
            flags |= Pattern.UNICODE_CASE;
            break;
        case 'd':
            flags |= Pattern.UNIX_LINES;
            break;
        }
    }
    return flags;
}

From source file:com.swordlord.gozer.databinding.DataBindingMember.java

private void parseBindingMember() {
    // probably throw error in this case? -> no. DataBinding can be NULL!
    if (_strDataBindingMember == null) {
        return;/*from  w w w.ja v  a 2  s . co  m*/
    }

    Pattern pattern = Pattern.compile(
            "^(@)?([a-z_0-9]*)(\\{[(\\?)?a-z_0-9,:='%\\s@\\[\\]\\(\\)]*\\})?(\\[[0-9]*\\])?$",
            Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);

    String[] bmElements = _strDataBindingMember.split("\\.");
    if (bmElements.length == 0) {
        LOG.error("Split of binding member return 0 elements: " + _strDataBindingMember);
        return;
    }

    // reset this, is no problem since works with lazy initialisation
    _strBindingPathName = null;
    int iElement = 0;

    for (String strBindingMemberElement : bmElements) {
        Matcher matcher = pattern.matcher(strBindingMemberElement);

        if (!matcher.find()) {
            LOG.error("DataBinding parser can't parse binding member: " + strBindingMemberElement);
            return;
        }

        if (matcher.groupCount() != 4) {
            LOG.error("Wrong group count during parsing of binding member element: " + strBindingMemberElement
                    + " in binding member: " + _strDataBindingMember);
            return;
        }

        DataBindingElement element = new DataBindingElement();

        element.setPathElement(matcher.group(2));

        String strFilter = matcher.group(3);
        if ((strFilter != null) && (strFilter.length() > 2)) {
            try {
                element.setFilter(strFilter.substring(1, strFilter.length() - 1));
            } catch (IndexOutOfBoundsException e) {
                LOG.error("strFilter is defect: " + strFilter);
                LOG.debug(e.getMessage());
                return;
            }
        }

        String strRowNumber = matcher.group(4);
        if ((strRowNumber != null) && (strRowNumber.length() > 2)) {
            try {
                element.setRowNumber(Integer.parseInt(strRowNumber.substring(1, strRowNumber.length() - 1)));
            } catch (NumberFormatException e) {
                LOG.error("RowNumber is not of type integer: " + strRowNumber);
                LOG.debug(e.getMessage());
                return;
            } catch (IndexOutOfBoundsException e) {
                LOG.error("RowNumber is defect: " + strRowNumber);
                LOG.debug(e.getMessage());
                return;
            }
        } else {
            if (iElement < bmElements.length - 1) {
                // wrong syntax, add 0 on our own
                element.setRowNumber(0);
                //element.isField(true);
            } else {
                element.setField(true);
            }
        }

        _dataBindingElements.add(element);

        iElement++;
    }
}

From source file:azkaban.project.ProjectManager.java

public List<Project> getUserProjectsByRegex(User user, String regexPattern) {
    List<Project> array = new ArrayList<Project>();
    Pattern pattern;//from   ww w .jav a  2s.  c o m
    try {
        pattern = Pattern.compile(regexPattern, Pattern.CASE_INSENSITIVE);
    } catch (PatternSyntaxException e) {
        logger.error("Bad regex pattern " + regexPattern);
        return array;
    }

    for (Project project : projectsById.values()) {
        Permission perm = project.getUserPermission(user);

        if (perm != null && (perm.isPermissionSet(Type.ADMIN) || perm.isPermissionSet(Type.READ))) {
            if (pattern.matcher(project.getName()).find()) {
                array.add(project);
            }
        }
    }
    return array;
}

From source file:com.mmj.app.web.controller.search.SearchController.java

public static String ignoreCaseReplace(String source, String pattern) {
    Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
    Matcher mc = p.matcher(source);
    StringBuffer sb = new StringBuffer();
    while (mc.find()) {
        mc.appendReplacement(sb, "<em class='highlight'>" + mc.group() + "</em>");
    }//  ww  w.  j  a  v  a 2 s. c  o m
    mc.appendTail(sb);
    return sb.toString();
}

From source file:com.opensymphony.xwork2.validator.URLValidatorTest.java

public void testValidUrlWithDefaultRegex() throws Exception {
    URLValidator validator = new URLValidator();

    Pattern pattern = Pattern.compile(validator.getUrlRegex(), Pattern.CASE_INSENSITIVE);

    assertFalse(pattern.matcher("myapp://test.com").matches());
    assertFalse(pattern.matcher("myap://test.com").matches());
    assertFalse(pattern.matcher("").matches());
    assertFalse(pattern.matcher("   ").matches());
    assertFalse(pattern.matcher("no url").matches());
    assertFalse(pattern.matcher(//  w w  w  .  j  a  va2s .co m
            "http://example.com////////////////////////////////////////////////////////////////////////////////////??")
            .matches());

    assertTrue(pattern.matcher("http://www.opensymphony.com").matches());
    assertTrue(pattern.matcher("https://www.opensymphony.com").matches());
    assertTrue(pattern.matcher("https://www.opensymphony.com:443/login").matches());
    assertTrue(pattern.matcher("http://localhost:8080/myapp").matches());

    assertTrue(pattern.matcher(
            "http://www.legalspace.com/__media__/js/netsoltrademark.php?d=www.a-vos-travaux.fr%2Facheter-un-aspirateur-sans-sac-pas-cher%2F")
            .matches());
    assertTrue(UrlValidator.getInstance().isValid(
            "http://www.legalspace.com/__media__/js/netsoltrademark.php?d=www.a-vos-travaux.fr%2Facheter-un-aspirateur-sans-sac-pas-cher%2F"));

    assertTrue(pattern.matcher(
            "http://www.duadmin.isaev.Infoduadmin.Isaev.info/?a%5B%5D=%3Ca%20href%3Dhttp%3A%2F%2Fwww.aspert.fr%2Fun-seche-cheveux-lisseur-est-il-vraiment-utile%2F%3Eseche%20cheveux%20dyson%20test%3C%2Fa")
            .matches());
    assertTrue(UrlValidator.getInstance().isValid(
            "http://www.duadmin.isaev.Infoduadmin.Isaev.info/?a%5B%5D=%3Ca%20href%3Dhttp%3A%2F%2Fwww.aspert.fr%2Fun-seche-cheveux-lisseur-est-il-vraiment-utile%2F%3Eseche%20cheveux%20dyson%20test%3C%2Fa"));

    assertTrue(pattern.matcher(
            "http://netsol-underconstruction-page-monitor-1.com/__media__/js/netsoltrademark.php?d=www.le-soutien-scolaire.fr%2Favis-et-test-comparatifs-des-robots-multifonctions%2F")
            .matches());
    assertTrue(UrlValidator.getInstance().isValid(
            "http://netsol-underconstruction-page-monitor-1.com/__media__/js/netsoltrademark.php?d=www.le-soutien-scolaire.fr%2Favis-et-test-comparatifs-des-robots-multifonctions%2F"));
}