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:my.madet.function.HttpParser.java

/**
 * //from   w  w  w  . j  a v  a2  s.  com
 * @param html
 * @return
 */
public boolean StatusNotBlocked() {
    String url = "http://info.uniten.edu.my/info/Ticketing.ASP?WCI=LedgerBalance";
    // fetch html from url
    String html = FetchUrL(url);
    if (html == null)
        return false;

    Pattern pattern = Pattern.compile("you are not blocked", Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(html);
    if (matcher.find()) {
        //found the string
        return true;
    } else
        return false;
}

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

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

    String fileContent = test.readFile();
    if (!isValidTestConfiguration()) {
        return;//from   www.  jav a 2 s  .  c o 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:com.ponysdk.impl.query.memory.FilteringTools.java

public static <T> List<T> filter(final List<T> datas, final String fieldKey, final Object value) {
    if (value == null || datas == null || fieldKey.equals(EMPTY)) {
        return datas;
    }/* w  ww .j  av a2s .c o m*/
    final List<T> validData = new ArrayList<>();
    try {
        final String[] pathDetails = fieldKey.split(DOT_REGEX);
        for (final T data : datas) {
            final Object val = getValue(data, pathDetails);
            if (val == null)
                continue;
            if (value.equals(val)) {
                validData.add(data);
                continue;
            }
            // Now we can filter our data against the pattern
            final String text = normalisePattern(value.toString().trim());
            final Pattern pattern = Pattern.compile(REGEX_BEGIN + text + REGEX_END, Pattern.CASE_INSENSITIVE);
            Matcher matcher;
            if (val instanceof Collection<?>) {
                final Collection<?> collection = (Collection<?>) val;
                for (final Object item : collection) {
                    matcher = pattern.matcher(item.toString());
                    if (matcher.find()) {
                        validData.add(data);
                        break;
                    }
                }
                if (collection.isEmpty()) {
                    matcher = pattern.matcher("");
                    if (matcher.find()) {
                        validData.add(data);
                    }
                }
            } else if (val.toString() != null) {
                matcher = pattern.matcher(val.toString());
                if (matcher.find()) {
                    validData.add(data);
                } else {
                    matcher = pattern.matcher("");
                    if (matcher.find()) {
                        validData.add(data);
                    }
                }
            }
        }
    } catch (final PatternSyntaxException e) {
        if (log.isDebugEnabled()) {
            log.debug("bad pattern : " + value);
        }
    } catch (final Exception e) {
        log.error("Filter Error => pattern : " + value + " , property : " + fieldKey, e);
    }
    return validData;
}

From source file:edu.jhuapl.dorset.agents.StockAgent.java

protected CompanyInfo findStockSymbol(String stockCompanyName) {
    CompanyInfo companyInfo = null;//  w w  w  .  j a v a2s.  c om
    ArrayList<String> regexMatches = new ArrayList<String>();

    if (this.stockSymbolMap.get(stockCompanyName) != null) {
        companyInfo = this.stockSymbolMap.get(stockCompanyName);

    } else {
        String regex = "\\b" + stockCompanyName + "\\b";

        Pattern pat = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);

        for (Map.Entry<String, CompanyInfo> entry : stockSymbolMap.entrySet()) {
            Matcher matcher = pat.matcher(entry.getKey());

            if (matcher.find()) {
                regexMatches.add(entry.getKey());
            }
        }

        if (regexMatches.size() == 0) {
            companyInfo = null;
        } else if (regexMatches.size() == 1) {
            companyInfo = this.stockSymbolMap.get(regexMatches.get(0));

        } else {
            int distance;
            HashMap<String, Integer> matchDistanceMap = new HashMap<String, Integer>();
            for (int i = 0; i < regexMatches.size(); i++) {
                distance = (StringUtils.getLevenshteinDistance(regexMatches.get(i), stockCompanyName));
                matchDistanceMap.put(regexMatches.get(i), distance);
            }

            Entry<String, Integer> minDistancePair = null;
            for (Entry<String, Integer> entry : matchDistanceMap.entrySet()) {
                if (minDistancePair == null || minDistancePair.getValue() > entry.getValue()) {
                    minDistancePair = entry;
                }
            }

            companyInfo = this.stockSymbolMap.get(minDistancePair.getKey());

        }

    }

    return companyInfo;
}

From source file:de.mpg.escidoc.services.syndication.Utils.java

/**
 * Version of the <code>String.replaceAll(what, expr, replacement)</code>
 * which ignores new line breaks and case sensitivity  
 * @param what is string to be replaced/*from  w w  w .java 2 s.  co m*/
 * @param expr is RegExp
 * @param replacement 
 * @return replaced <code>what</code>
 */
public static String replaceAllTotal(String what, String expr, String replacement) {
    return Pattern.compile(expr, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(what)
            .replaceAll(replacement);
}

From source file:gtu._work.ui.LoadJspFetchJavascriptUI.java

private void executeBtnActionPerformed(ActionEvent evt) {
    try {/*from  ww w  .  j av a 2s .c  o  m*/
        String subName = Validate.notBlank(subNameText.getText());
        if (StringUtils.isNotBlank(tagPatternText.getText())) {
            String startP = "\\<" + tagPatternText.getText();
            String endP = "\\<\\/" + tagPatternText.getText() + "\\>";
            javascriptStart = Pattern.compile(startP, Pattern.CASE_INSENSITIVE);
            javascriptEnd = Pattern.compile(endP, Pattern.CASE_INSENSITIVE);
            JCommonUtil._jOptionPane_showMessageDialog_info(
                    String.format("tagPattern:\nstart:\n%send:\n%s", startP, endP));
        }

        long startTime = System.currentTimeMillis();

        File file = JCommonUtil.filePathCheck(filePathText.getText(), "?", false);
        List<File> fileList = new ArrayList<File>();
        if (file.isFile()) {
            fileList.add(file);
        } else {
            if (subName.startsWith(".")) {
                subName = subName.substring(1);
            }
            FileUtil.searchFilefind(file, ".*\\." + subName + "$", fileList);
        }
        File outputFile = new File(FileUtil.DESKTOP_PATH,
                "javascript_" + DateUtil.getCurrentDateTime(false) + ".txt");
        BufferedWriter writer = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(outputFile), "utf8"));
        for (File f : fileList) {
            String content = writeScript(f);
            if (content.length() > 0) {
                writer.write(
                        "#start#" + f.getAbsolutePath() + "#==============================================");
                writer.newLine();
                writer.write(content);
                writer.write(
                        "#end  #" + f.getAbsolutePath() + "#==============================================");
                writer.newLine();
            }
        }
        writer.flush();
        writer.close();

        long duringTime = System.currentTimeMillis() - startTime;

        JCommonUtil._jOptionPane_showMessageDialog_info(
                "?,:" + fileList.size() + "\n:" + duringTime);
    } catch (Exception ex) {
        JCommonUtil.handleException(ex);
    }
}

From source file:com.tqlab.plugin.mybatis.generator.SqlTempleatePluginAdapter.java

@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass,
        IntrospectedTable introspectedTable) {
    // Check use cache or not
    this.checkCache(interfaze);

    final String tableName = introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime();
    DbTable dbTable = this.map.get(tableName.toLowerCase());
    if (null == dbTable) {
        return true;
    }/*from   w w w.  j a  v  a  2  s . co  m*/

    final FullyQualifiedJavaType parameterType = introspectedTable.getRules().calculateAllFieldsClass();
    interfaze.addImportedType(parameterType);

    final AnnotatedGenerator generator = new AnnotatedGenerator();
    generator.setContext(context);
    generator.setIntrospectedTable(introspectedTable);

    for (DbTableOperation operation : dbTable.getOperations()) {

        String sqlStr = SqlUtil.trimSql(operation.getSql());
        // parse include <include refid="userColumns"/>
        Matcher matcher = Pattern.compile(INCLUDE, Pattern.CASE_INSENSITIVE).matcher(sqlStr);
        while (matcher.find()) {
            String s = matcher.group();
            Element e = SqlTemplateParserUtil.parseXml(s.replace("\\", ""));
            String id = e.attributeValue("refid");
            DbSql sqlInclude = dbTable.getSqls().get(id);
            if (null != sqlInclude) {
                sqlStr = sqlStr.replace(s, sqlInclude.getSql());
            }
        }
        final String sql = sqlStr;
        final boolean hasScript = ScriptUtil.hasScript(operation.getSql());
        Statement statement = this.getStatement(sql, hasScript);

        final Method method = new Method();
        method.setReturnType(getReturnFullyQualifiedJavaType(operation, interfaze, introspectedTable,
                parameterType, statement));
        method.setVisibility(JavaVisibility.PUBLIC);
        method.setName(operation.getId());
        final String[] comments = operation.getComment() == null ? null : operation.getComment().split("\n");
        addGeneralMethodComment(method, introspectedTable, comments);
        final Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();

        final List<Parameter> list = this.parseSqlParameter(operation.getParameterType(), sql, hasScript,
                operation.getParams());

        if (hasScript) {
            importedTypes
                    .add(new FullyQualifiedJavaType("org.apache.ibatis.scripting.xmltags.XMLLanguageDriver"));
            importedTypes.add(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Lang"));
            method.addAnnotation("@Lang(XMLLanguageDriver.class)");
        }

        if (list.size() == 1 && list.get(0).getType().equals(FullyQualifiedJavaType.getObjectInstance())) {
            Parameter p = list.get(0);
            list.clear();
            Parameter newParam = new Parameter(p.getType(), p.getName());
            list.add(newParam);
        } else if (list.size() > 0) {
            importedTypes.add(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Param")); //$NON-NLS-1$
        }

        for (Parameter p : list) {
            method.addParameter(p); //$NON-NLS-1$
            importedTypes.add(p.getType());
        }

        if (null != operation.getOptions() && operation.getOptions().size() > 0) {
            importedTypes.add(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Options"));

            StringBuilder buf = new StringBuilder();
            for (DbOption option : operation.getOptions()) {
                String name = option.getName();
                buf.append(name);
                buf.append("=");
                if (name.equals("keyProperty") || name.equals("keyColumn")) {
                    buf.append("\"");
                    buf.append(option.getValue());
                    buf.append("\"");
                } else {
                    buf.append(option.getValue());
                }
                buf.append(" ");
            }
            method.addAnnotation("@Options(" + buf.toString().trim() + ")");
        }

        generator.addMapperAnnotations(interfaze, method, operation.getResult(), statement, hasScript, sql);
        interfaze.addMethod(method);
        interfaze.addImportedTypes(importedTypes);

        if (null != operation.getResult()) {
            interfaze.addImportedType(operation.getResult().getType());
        }
    }

    return true;
}

From source file:cloudlens.engine.CL.java

public boolean findRegex(String regex, String input) {
    final Pattern pat = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
    final Matcher m = pat.matcher(input);
    return m.find();
}

From source file:com.quinsoft.zeidon.standardoe.ApplicationImpl.java

@Override
public List<String> getLodNameList(Task task) {
    ClassLoader loader = this.getClass().getClassLoader();
    final String resourceDir = getObjectDir() + "/";

    Pattern pattern = Pattern.compile("(.*)(\\.xod$)", Pattern.CASE_INSENSITIVE);
    try {// w  ww.  jav a2s  .c om
        return (List<String>) IOUtils.readLines(loader.getResourceAsStream(resourceDir), StandardCharsets.UTF_8)
                .stream().map(resourceName -> pattern.matcher(resourceName)) // Create a matcher
                .filter(matcher -> matcher.matches()) // Keep only ones that match.
                .map(matcher -> matcher.group(1)) // Get the base filename.
                .collect(Collectors.toList());
    } catch (IOException e) {
        throw ZeidonException.wrapException(e).appendMessage("XOD resource dir: %s", resourceDir);
    }

}

From source file:com.wordnik.swaggersocket.server.SwaggerSocketProtocolInterceptor.java

public SwaggerSocketProtocolInterceptor includedheaders(String p) {
    if (p != null) {
        this.includedheaders = Pattern.compile(p, Pattern.CASE_INSENSITIVE);
    }/*from   w  w  w  .j  a v  a 2s .c o  m*/
    return this;
}