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.eu.evaluation.server.dao.AbstractDAO.java

/**
 * jpqlorder By??//  www.  ja v  a  2 s .  c  o m
 *
 * @param jpql
 * @return
 */
private static String removeOrders(String jpql) {
    Pattern p = Pattern.compile("order\\s*by[\\w|\\W|\\s|\\S]*", Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(jpql);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        m.appendReplacement(sb, "");
    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:de.betterform.xml.xforms.xpath.BetterFormXPathFunctions.java

/**
 * <code>Regexp</code> is a utility class providing the functionality
 * present within the EXSLT Regular Expressions definition (<a
 * href="http://www.exslt.org/regexp"//from  w ww  .j a v a  2  s .c  o  m
 * target="_top">http://www.exslt.org/regexp</a>). <br>
 * <br>
 * This is a contribution from Terence Jacyno. <p/> Todo: Move to
 * 'ExsltRegExpExtensionFunctions, rename to 'test', add 'replace' and
 * 'match'
 */
public static boolean match(String input, String regex, String flags) {

    String regexKey = ((flags == null) || (flags.indexOf('i') == -1)) ? "s " + regex : "i " + regex;

    Pattern pattern = (Pattern) m_regexPatterns.get(regexKey);

    if (pattern == null) {
        pattern = (regexKey.charAt(0) == 'i') ? Pattern.compile(regex, Pattern.CASE_INSENSITIVE)
                : Pattern.compile(regex);
        m_regexPatterns.put(regexKey, pattern);
    }

    Matcher matcher = pattern.matcher(input);
    return matcher.matches();
}

From source file:com.clustercontrol.agent.util.MonitorStringUtil.java

/**
 * ???????/*w  ww  . java  2  s. c  o  m*/
 * @param line 
 * @param generationDate ?
 * @param monitorInfo 
 */
public static void patternMatch(String line, MonitorInfo monitorInfo, RunInstructionInfo runInstructionInfo,
        Date generationDate, String filename) {
    if (runInstructionInfo == null && monitorInfo.getCalendar() != null
            && !CalendarWSUtil.isRun(monitorInfo.getCalendar())) {
        m_log.debug("patternMatch is skipped because of calendar");
        return;
    }

    boolean processed = false;
    if (runInstructionInfo != null || monitorInfo.isMonitorFlg()) {
        int order_no = 0;
        for (MonitorStringValueInfo stringInfo : monitorInfo.getStringValueInfo()) {
            ++order_no;
            if (m_log.isDebugEnabled()) {
                m_log.debug("patternMatch() line = " + line + ", monitorId = " + stringInfo.getMonitorId()
                        + ", orderNo = " + order_no + ", pattern = " + stringInfo.getPattern());
            }
            if (!stringInfo.isValidFlg()) {
                continue;
            }
            String patternText = stringInfo.getPattern();
            String message = line;
            m_log.trace("patternMatch check " + message);

            Pattern pattern = null;
            // ?????
            if (stringInfo.isCaseSensitivityFlg()) {
                pattern = Pattern.compile(patternText, Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
            }
            // ???
            else {
                pattern = Pattern.compile(patternText, Pattern.DOTALL);
            }
            Matcher matcher = pattern.matcher(line);

            if (matcher.matches()) {
                m_log.debug("patternMatch match " + message);

                // ???
                if (stringInfo.isProcessType()) {
                    MessageInfo logmsg = new MessageInfo();
                    logmsg.setMessage(line);

                    if (generationDate != null) {
                        m_log.debug("patternMatch set generation date : " + generationDate);
                        logmsg.setGenerationDate(generationDate.getTime());
                    } else {
                        logmsg.setGenerationDate(HinemosTime.getDateInstance().getTime());
                    }
                    logmsg.setHostName(Agent.getAgentInfo().getHostname());

                    MonitorInfo monitorInfo2 = new MonitorInfo();
                    if (filename != null) {
                        monitorInfo2.setApplication(monitorInfo.getApplication());
                        monitorInfo2.setCalendar(monitorInfo.getCalendar());
                        monitorInfo2.setCalendarId(monitorInfo.getCalendarId());
                        monitorInfo2.setCollectorFlg(monitorInfo.isCollectorFlg());
                        monitorInfo2.setCustomCheckInfo(monitorInfo.getCustomCheckInfo());
                        monitorInfo2.setCustomTrapCheckInfo(monitorInfo.getCustomTrapCheckInfo());
                        monitorInfo2.setDelayTime(monitorInfo.getDelayTime());
                        monitorInfo2.setDescription(monitorInfo.getDescription());
                        monitorInfo2.setFacilityId(monitorInfo.getFacilityId());
                        monitorInfo2.setFailurePriority(monitorInfo.getFailurePriority());
                        monitorInfo2.setHttpCheckInfo(monitorInfo.getHttpCheckInfo());
                        monitorInfo2.setHttpScenarioCheckInfo(monitorInfo.getHttpScenarioCheckInfo());
                        monitorInfo2.setItemName(monitorInfo.getItemName());
                        monitorInfo2.setJmxCheckInfo(monitorInfo.getJmxCheckInfo());

                        // ???????LogfileCheckInfo???????
                        LogfileCheckInfo logFileCheckInfo = new LogfileCheckInfo();
                        logFileCheckInfo.setDirectory(monitorInfo.getLogfileCheckInfo().getDirectory());
                        logFileCheckInfo.setFileEncoding(monitorInfo.getLogfileCheckInfo().getFileEncoding());
                        logFileCheckInfo.setFileName(monitorInfo.getLogfileCheckInfo().getFileName());
                        logFileCheckInfo
                                .setFileReturnCode(monitorInfo.getLogfileCheckInfo().getFileReturnCode());
                        logFileCheckInfo.setLogfile(monitorInfo.getLogfileCheckInfo().getLogfile());
                        logFileCheckInfo.setMaxBytes(monitorInfo.getLogfileCheckInfo().getMaxBytes());
                        logFileCheckInfo.setMonitorId(monitorInfo.getLogfileCheckInfo().getMonitorId());
                        logFileCheckInfo.setMonitorTypeId(monitorInfo.getLogfileCheckInfo().getMonitorTypeId());
                        logFileCheckInfo.setPatternHead(monitorInfo.getLogfileCheckInfo().getPatternHead());
                        logFileCheckInfo.setPatternTail(monitorInfo.getLogfileCheckInfo().getPatternTail());

                        monitorInfo2.setLogfileCheckInfo(logFileCheckInfo);// 
                        monitorInfo2.setLogFormatId(monitorInfo.getLogFormatId());
                        monitorInfo2.setMeasure(monitorInfo.getMeasure());
                        monitorInfo2.setMonitorFlg(monitorInfo.isMonitorFlg());
                        monitorInfo2.setMonitorId(monitorInfo.getMonitorId());
                        monitorInfo2.setMonitorType(monitorInfo.getMonitorType());
                        monitorInfo2.setMonitorTypeId(monitorInfo.getMonitorTypeId());
                        monitorInfo2.setNotifyGroupId(monitorInfo.getNotifyGroupId());
                        monitorInfo2.setOwnerRoleId(monitorInfo.getOwnerRoleId());
                        monitorInfo2.setPerfCheckInfo(monitorInfo.getPerfCheckInfo());
                        monitorInfo2.setPingCheckInfo(monitorInfo.getPingCheckInfo());
                        monitorInfo2.setPluginCheckInfo(monitorInfo.getPluginCheckInfo());
                        monitorInfo2.setPortCheckInfo(monitorInfo.getPortCheckInfo());
                        monitorInfo2.setProcessCheckInfo(monitorInfo.getProcessCheckInfo());
                        monitorInfo2.setRegDate(monitorInfo.getRegDate());
                        monitorInfo2.setRegUser(monitorInfo.getRegUser());
                        monitorInfo2.setRunInterval(monitorInfo.getRunInterval());
                        monitorInfo2.setScope(monitorInfo.getScope());
                        monitorInfo2.setSnmpCheckInfo(monitorInfo.getSnmpCheckInfo());
                        monitorInfo2.setSqlCheckInfo(monitorInfo.getSqlCheckInfo());
                        monitorInfo2.setTrapCheckInfo(monitorInfo.getTrapCheckInfo());
                        monitorInfo2.setTriggerType(monitorInfo.getTriggerType());
                        monitorInfo2.setUpdateDate(monitorInfo.getUpdateDate());
                        monitorInfo2.setUpdateUser(monitorInfo.getUpdateUser());
                        monitorInfo2.setWinEventCheckInfo(monitorInfo.getWinEventCheckInfo());
                        monitorInfo2.setWinServiceCheckInfo(monitorInfo.getWinServiceCheckInfo());

                        monitorInfo2.getLogfileCheckInfo().setLogfile(filename);
                    }

                    if (HinemosModuleConstant.MONITOR_LOGFILE.equals(monitorInfo.getMonitorTypeId())) {
                        if (filename != null) {
                            LogfileResultForwarder.getInstance().add(message, logmsg, monitorInfo2, stringInfo,
                                    runInstructionInfo);
                        } else {
                            LogfileResultForwarder.getInstance().add(message, logmsg, monitorInfo, stringInfo,
                                    runInstructionInfo);
                        }
                    } else if (HinemosModuleConstant.MONITOR_WINEVENT.equals(monitorInfo.getMonitorTypeId())) {
                        WinEventResultForwarder.getInstance().add(message, logmsg, monitorInfo, stringInfo,
                                runInstructionInfo);
                    }

                    processed = true;

                    m_log.debug("patternMatch send message : " + message);
                    m_log.debug("patternMatch send logmsg message : " + logmsg.getMessage());
                    m_log.debug("patternMatch send logmsg generation date : "
                            + new Date(logmsg.getGenerationDate()));
                    m_log.debug("patternMatch send logmsg hostname : " + logmsg.getHostName());
                }
                break;
            }
        }
    } else {
        m_log.debug("patternMatch is skipped because of monitor flg");
    }

    if (!processed && monitorInfo.isCollectorFlg()) {
        MessageInfo logmsg = new MessageInfo();
        logmsg.setMessage(line);
        if (generationDate != null) {
            m_log.debug("patternMatch set generation date : " + generationDate);
            logmsg.setGenerationDate(generationDate.getTime());
        } else {
            logmsg.setGenerationDate(HinemosTime.getDateInstance().getTime());
        }
        logmsg.setHostName(Agent.getAgentInfo().getHostname());

        if (filename != null) {
            monitorInfo.getLogfileCheckInfo().setLogfile(filename);
        }

        if (HinemosModuleConstant.MONITOR_LOGFILE.equals(monitorInfo.getMonitorTypeId())) {
            LogfileResultForwarder.getInstance().add(line, logmsg, monitorInfo, null, runInstructionInfo);
        } else if (HinemosModuleConstant.MONITOR_WINEVENT.equals(monitorInfo.getMonitorTypeId())) {
            WinEventResultForwarder.getInstance().add(line, logmsg, monitorInfo, null, runInstructionInfo);
        }
    } else {
        if (!processed)
            m_log.debug("collected no data.");
    }
}

From source file:de.raion.xmppbot.plugin.TfsIssuePlugin.java

/**
 * Instantiates config related stuff.//from   ww  w . ja  v  a  2s  .  co m
 */
private void init() {
    config = getContext().loadConfig(TfsConfig.class);
    acceptFilter = new MessageBodyMatchesFilter(config.getRegex());
    pattern = Pattern.compile(config.getRegex(), Pattern.CASE_INSENSITIVE);
    client = Client.create();
    HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter(config.getUser(), config.getPassword());
    client.addFilter(authFilter);
}

From source file:com.github.anba.test262.environment.RhinoEnv.java

@Override
public EcmaErrorMatcher<RhinoException> matcher(String errorType) {
    return new EcmaErrorMatcher<RhinoException>() {
        @Override//from   ww w. j a  va2s  .  com
        public boolean matches(RhinoException error, String errorType) {
            // errorType is now a regular expression
            Pattern p = Pattern.compile(errorType, Pattern.CASE_INSENSITIVE);
            String name;
            if (error instanceof EcmaError) {
                name = ((EcmaError) error).getName();
            } else if (error instanceof JavaScriptException) {
                Object value = ((JavaScriptException) error).getValue();
                if (value != null && value.getClass().getName().equals("org.mozilla.javascript.NativeError")) {
                    Object message = ((ScriptableObject) value).get("message");
                    name = ScriptRuntime.toString(message);
                } else {
                    name = error.details();
                }
            } else if (error instanceof EvaluatorException) {
                name = "SyntaxError";
            } else {
                name = "";
            }

            return p.matcher(name).find();
            // return errorType.equals(name);
        }

        @Override
        public Class<? extends RhinoException> exception() {
            return RhinoException.class;
        }
    };
}

From source file:com.github.ibole.infrastructure.persistence.db.mybatis.pagination.SqlHelper.java

public static boolean containRegex(String sql, String regex) {
    Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(sql);
    return matcher.find();
}

From source file:hu.bme.mit.sette.tools.catg.CatgParser.java

@Override
protected void parseSnippet(Snippet snippet, SnippetInputsXml inputsXml) throws Exception {
    File outputFile = RunnerProjectUtils.getSnippetOutputFile(getRunnerProjectSettings(), snippet);
    File errorFile = RunnerProjectUtils.getSnippetErrorFile(getRunnerProjectSettings(), snippet);

    if (errorFile.exists()) {
        // TODO enhance this section and make it more clear

        List<String> lines = FileUtils.readLines(errorFile);

        String firstLine = lines.get(0);

        if (firstLine.startsWith("Exception in thread \"main\"")) {
            Pattern p = Pattern.compile("Exception in thread \"main\" ([a-z0-9\\._]+).*",
                    Pattern.CASE_INSENSITIVE);

            Matcher m = p.matcher(firstLine);
            if (m.matches()) {
                String exceptionType = m.group(1);

                if (exceptionType.equals("java.lang.NoClassDefFoundError")) {
                    inputsXml.setResultType(ResultType.NA);
                } else if (exceptionType.equals("java.lang.VerifyError")) {
                    inputsXml.setResultType(ResultType.EX);
                } else if (exceptionType.endsWith("Exception")) {
                    // enhance
                    inputsXml.setResultType(ResultType.EX);
                } else {
                    System.err.println(snippet.getMethod());
                    System.err.println("NOT HANDLED TYPE: " + exceptionType);
                }/* w w w. j av a 2 s  .c  o  m*/
            } else {
                System.err.println(snippet.getMethod());
                System.err.println("NO MATCH");
            }
        } else if (firstLine.startsWith("java.lang.ArrayIndexOutOfBoundsException")) {
            inputsXml.setResultType(ResultType.EX);
        } else if (firstLine.startsWith("WARNING: !!!!!!!!!!!!!!!!! Prediction failed !!!!!!!!!!!!!!!!!")) {
            // TODO enhance (it was just warning)
            inputsXml.setResultType(ResultType.S);
        }

        // if (firstLine
        // .startsWith("Exception in thread \"main\" java.lang.NoClassDefFoundError"))
        // {
        // inputsXml.setResultType(ResultType.NA);
        // return;
        // } else if (firstLine
        // .startsWith("Exception in thread \"main\" java.lang.StringIndexOutOfBoundsException"))
        // {
        // inputsXml.setResultType(ResultType.EX);
        // return;
        // }// else if(firstLine.startsWith("))

        // TODO enhance error message

        // this is debug (only if unhandled error)
        if (inputsXml.getResultType() == null) {
            System.err.println("=============================");
            System.err.println(snippet.getMethod());
            System.err.println("=============================");

            for (String line : lines) {
                System.err.println(line);
            }
            System.err.println("=============================");
        }
    } else {
        // TODO enhance this section
        inputsXml.setResultType(ResultType.S);

        // collect inputs
        List<String> lines = FileUtils.readLines(outputFile);
        if (!lines.get(0).startsWith("Now testing ")) {
            throw new RuntimeException("File beginning problem: " + outputFile);
        }

        Pattern p = Pattern.compile("\\[Input (\\d+)\\]");
        Pattern p2 = Pattern.compile("  (\\w+) param(\\d+) = (.*)");

        int inputNumber = 1;

        for (int i = 1; i < lines.size(); inputNumber++) {
            String line = lines.get(i);

            Matcher m = p.matcher(line);
            if (m.matches()) {
                if (!m.group(1).equals(String.valueOf(inputNumber))) {
                    System.err.println("Current input should be: " + inputNumber);
                    System.err.println("Current input line: " + line);
                    throw new RuntimeException("File input problem (" + line + "): " + outputFile);
                }

                // find end of generated input
                int nextInputLine = -1;
                for (int j = i + 1; j < lines.size(); j++) {
                    if (p.matcher(lines.get(j)).matches()) {
                        nextInputLine = j;
                        break;
                    }
                }

                if (nextInputLine < 0) {
                    // EOF
                    nextInputLine = lines.size();
                }

                int paramCount = snippet.getMethod().getParameterTypes().length;

                InputElement ie = new InputElement();

                for (int j = 0; j < paramCount; j++) {
                    String l = lines.get(i + 1 + j + 1);
                    Matcher m2 = p2.matcher(l);

                    if (m2.matches()) {
                        String type = m2.group(1);
                        String value = m2.group(3);

                        ParameterElement pe = new ParameterElement();

                        if (type.equals("String")) {
                            pe.setType(ParameterType.EXPRESSION);
                            pe.setValue("\"" + value + "\"");
                        } else {
                            pe.setType(ParameterType.fromString(type));
                            pe.setValue(value);
                        }

                        ie.getParameters().add(pe);
                    } else {
                        throw new RuntimeException("File input problem (" + l + "): " + outputFile);
                    }
                }

                inputsXml.getGeneratedInputs().add(ie);

                i = nextInputLine;

                // TODO now NOT dealing with result and exception
            } else {
                throw new RuntimeException("File input problem (" + line + "): " + outputFile);
            }
        }
    }

}

From source file:com.zilotti.utils.NetworkUtils.java

/**
 * Validates a host name./*w w  w.  j  a v a  2s.com*/
 *
 * @param value
 * @return
 */
public static boolean isHostName(String value) {
    if (value == null)
        return false;

    /*
     * A valid domain can be 63 chars long with out the extension or 67
     * chars long with it. We should be getting them with extenstions so
     * we allow the 67 length. 
     */
    if (value.length() > 67) {
        return false;
    }

    Pattern p = Pattern.compile("^(?=.*?[a-z])(?!\\.)[a-z\\d.-]*[a-z\\d]$", Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(value);

    return m.matches();
}

From source file:com.streamreduce.core.dao.UserDAO.java

public User findUserForAlias(Account account, String alias) {
    return ds.createQuery(entityClazz).field("alias")
            .equal(Pattern.compile("^\\Q" + alias + "\\E$", Pattern.CASE_INSENSITIVE)).field("account")
            .equal(account).get();/* w w  w  .java2 s  .co m*/
}

From source file:edu.harvard.i2b2.crc.dao.setfinder.querybuilder.temporal.TemporalQuerySimpleSqlParser.java

private String runRegExExpression(String sqlString, String regEx) {
    Pattern p = Pattern.compile(regEx, Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(sqlString);
    if (m.find() && m.groupCount() > 0)
        return m.group(1).trim();
    else//from   ww w.ja  v a 2  s  . c o  m
        return null;
}