Example usage for java.util.regex Pattern MULTILINE

List of usage examples for java.util.regex Pattern MULTILINE

Introduction

In this page you can find the example usage for java.util.regex Pattern MULTILINE.

Prototype

int MULTILINE

To view the source code for java.util.regex Pattern MULTILINE.

Click Source Link

Document

Enables multiline mode.

Usage

From source file:org.rzo.yajsw.os.posix.bsd.macosx.MacOsXService.java

public int getPid() {
    try {// w  ww .jav  a  2 s . c  om
        String sp = String.format("^(\\d+).*\\s*%1$s$", _plistName);
        Pattern p = Pattern.compile(sp, Pattern.MULTILINE);
        String list = _utils.osCommand("launchctl list", 5000);
        Matcher m = p.matcher(list);
        m.find();
        int pid = Integer.parseInt(m.group(1));
        return pid;
    } catch (Exception ex) {
        // ex.printStackTrace();
    }

    return -1;

}

From source file:com.thoughtworks.go.domain.materials.git.GitCommandTest.java

@Test
void shouldOutputSubmoduleRevisionsAfterUpdate() throws Exception {
    GitRepoContainingSubmodule submoduleRepos = new GitRepoContainingSubmodule(temporaryFolder);
    submoduleRepos.addSubmodule(SUBMODULE, "sub1");
    GitCommand gitWithSubmodule = new GitCommand(null, createTempWorkingDirectory(),
            GitMaterialConfig.DEFAULT_BRANCH, false, null);
    gitWithSubmodule.clone(inMemoryConsumer(), submoduleRepos.mainRepo().getUrl());
    InMemoryStreamConsumer outConsumer = new InMemoryStreamConsumer();
    gitWithSubmodule.resetWorkingDir(outConsumer, new StringRevision("HEAD"), false);
    Matcher matcher = Pattern
            .compile(".*^\\s[a-f0-9A-F]{40} sub1 \\(heads/master\\)$.*", Pattern.MULTILINE | Pattern.DOTALL)
            .matcher(outConsumer.getAllOutput());
    assertThat(matcher.matches()).isTrue();
}

From source file:edu.scripps.fl.pubchem.web.session.PCWebSession.java

/**
 * /*from  w  w  w  .  j  a  v a 2s  .  c o  m*/
 * Returns counts of active, all, inactive, inconclusive and probe
 * substances in the aid.
 * 
 * @param aid
 * @return OutComeCount
 * @throws Exception
 */
public PCOutcomeCounts getSubstanceOutcomeCounts(int aid) throws Exception {
    PCOutcomeCounts oc = null;
    Document doc = getDocument("http://" + SITE + "/assay/assay.cgi?aid=" + aid);
    Node node = doc.selectSingleNode("//div[@id='uptsub']");
    //      Node node = doc.selectSingleNode("//b[. = 'Links:']");
    //Node node = doc.selectSingleNode("//b[. = 'Substances: ']");
    if (node != null) {
        node = node.getParent();
        AppendingVisitorSupport visitor = new AppendingVisitorSupport();
        node.accept(visitor);
        String text = visitor.getText();
        Pattern sectionPattern = Pattern.compile("Tested Substances(.+)", Pattern.DOTALL | Pattern.MULTILINE);
        Matcher matcher = sectionPattern.matcher(text);
        Boolean found = matcher.find();
        if (found) {
            text = matcher.group(1);
            Pattern countPattern;
            if (text.contains("("))
                countPattern = Pattern.compile("([\\w]+)\\((\\d+)\\)");
            else
                countPattern = Pattern.compile("([\\w]+):\\s+(\\d+)");

            matcher = countPattern.matcher(text);
            oc = new PCOutcomeCounts();
            while (matcher.find()) {
                String outcome = matcher.group(1);
                int count = Integer.parseInt(matcher.group(2));
                if ("All".equalsIgnoreCase(outcome))
                    oc.all = count;
                else if (outcome.contains("All"))
                    oc.all = count;
                else if ("Active".equalsIgnoreCase(outcome))
                    oc.active = count;
                else if ("Inactive".equalsIgnoreCase(outcome))
                    oc.inactive = count;
                else if ("Inconclusive".equalsIgnoreCase(outcome))
                    oc.inconclusive = count;
                else if ("Probe".equalsIgnoreCase(outcome))
                    oc.probe = count;
            }
        }
    }
    return oc;
}

From source file:com.evandroid.musica.MainLyricActivity.java

private String getIdUrl(String extra) {
    final Pattern urlPattern = Pattern.compile(
            "(?:^|[\\W])((ht|f)tp(s?):\\/\\/|www\\.)" + "(([\\w\\-]+\\.){1,}?([\\w\\-.~]+\\/?)*"
                    + "[\\p{Alnum}.,%_=?&#\\-+()\\[\\]\\*$~@!:/{};']*)",
            Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);

    Matcher matcher = urlPattern.matcher(extra);
    if (matcher.find())
        return extra.substring(matcher.start(), matcher.end());
    else/*  w  w  w  . j  a  va2s  .co m*/
        return null;
}

From source file:fr.inria.oak.paxquery.pact.operations.RecordPredicateEvaluation.java

private static boolean evaluateSimplePredicate(NestedMetadata inputRecordSignature, Record record,
        SimplePredicate simplePred) {/*  w ww .  j  a va 2 s  . com*/
    try {
        String numericPattern = "^-?\\d+([,\\.]\\d+)?([eE]-?\\d+)?$";
        boolean isValue1Number, isValue2Number;

        double value1, value2;

        //We are evaluating a predicate over two columns!
        if (simplePred.getStringConstant() == null && simplePred.getDoubleConstant() == -1) {
            switch (simplePred.getPredCode()) {
            case PREDICATE_EQUAL:
                isValue1Number = Pattern.matches(numericPattern,
                        record.getField(simplePred.getColumn1(), StringValue.class).getValue());
                isValue2Number = Pattern.matches(numericPattern,
                        record.getField(simplePred.getColumn2(), StringValue.class).getValue());
                if (isValue1Number && isValue2Number) {
                    //both columns contain numbers
                    value1 = Double.parseDouble(
                            record.getField(simplePred.getColumn1(), StringValue.class).getValue());
                    if (simplePred.getOperation1() != null)
                        value1 = simplePred.getOperation1().calculate(value1);
                    value2 = Double.parseDouble(
                            record.getField(simplePred.getColumn2(), StringValue.class).getValue());
                    if (simplePred.getOperation2() != null)
                        value2 = simplePred.getOperation2().calculate(value2);
                    return value1 == value2;
                } else if (!isValue1Number && !isValue2Number) //both columns contain non-number strings
                    return record
                            .getField(simplePred.getColumn1(),
                                    MetadataTypesMapping.getValueClass(
                                            inputRecordSignature.getType(simplePred.getColumn1())))
                            .equals(record.getField(simplePred.getColumn2(), MetadataTypesMapping
                                    .getValueClass(inputRecordSignature.getType(simplePred.getColumn2()))));
                else //a number and a non-number, result must be false
                    return false;
            case PREDICATE_NOTEQUAL:
                isValue1Number = Pattern.matches(numericPattern,
                        record.getField(simplePred.getColumn1(), StringValue.class).getValue());
                isValue2Number = Pattern.matches(numericPattern,
                        record.getField(simplePred.getColumn2(), StringValue.class).getValue());
                if (isValue1Number && isValue2Number) {
                    //both columns contain numbers
                    value1 = Double.parseDouble(
                            record.getField(simplePred.getColumn1(), StringValue.class).getValue());
                    if (simplePred.getOperation1() != null)
                        value1 = simplePred.getOperation1().calculate(value1);
                    value2 = Double.parseDouble(
                            record.getField(simplePred.getColumn2(), StringValue.class).getValue());
                    if (simplePred.getOperation2() != null)
                        value2 = simplePred.getOperation2().calculate(value2);
                    return value1 != value2;
                } else //at least one column contains a non-number, test for non-equality
                    return !record
                            .getField(simplePred.getColumn1(),
                                    MetadataTypesMapping.getValueClass(
                                            inputRecordSignature.getType(simplePred.getColumn1())))
                            .equals(record.getField(simplePred.getColumn2(), MetadataTypesMapping
                                    .getValueClass(inputRecordSignature.getType(simplePred.getColumn2()))));
            case PREDICATE_SMALLEROREQUALTHAN:
                value1 = Double
                        .parseDouble(record.getField(simplePred.getColumn1(), StringValue.class).getValue());
                if (simplePred.getOperation1() != null)
                    value1 = simplePred.getOperation1().calculate(value1);
                value2 = Double
                        .parseDouble(record.getField(simplePred.getColumn2(), StringValue.class).getValue());
                if (simplePred.getOperation2() != null)
                    value2 = simplePred.getOperation2().calculate(value2);
                return value1 <= value2;
            case PREDICATE_SMALLERTHAN:
                value1 = Double
                        .parseDouble(record.getField(simplePred.getColumn1(), StringValue.class).getValue());
                if (simplePred.getOperation1() != null)
                    value1 = simplePred.getOperation1().calculate(value1);
                value2 = Double
                        .parseDouble(record.getField(simplePred.getColumn2(), StringValue.class).getValue());
                if (simplePred.getOperation2() != null)
                    value2 = simplePred.getOperation2().calculate(value2);
                return value1 < value2;
            case PREDICATE_GREATEROREQUALTHAN:
                value1 = Double
                        .parseDouble(record.getField(simplePred.getColumn1(), StringValue.class).getValue());
                if (simplePred.getOperation1() != null)
                    value1 = simplePred.getOperation1().calculate(value1);
                value2 = Double
                        .parseDouble(record.getField(simplePred.getColumn2(), StringValue.class).getValue());
                if (simplePred.getOperation2() != null)
                    value2 = simplePred.getOperation2().calculate(value2);
                return value1 >= value2;
            case PREDICATE_GREATERTHAN:
                value1 = Double
                        .parseDouble(record.getField(simplePred.getColumn1(), StringValue.class).getValue());
                if (simplePred.getOperation1() != null)
                    value1 = simplePred.getOperation1().calculate(value1);
                value2 = Double
                        .parseDouble(record.getField(simplePred.getColumn2(), StringValue.class).getValue());
                if (simplePred.getOperation2() != null)
                    value2 = simplePred.getOperation2().calculate(value2);
                return value1 > value2;
            default:
                throw new PAXQueryExecutionException(
                        "Predicate " + simplePred.toString() + " not implemented yet!");
            }
        } else if (simplePred.getDoubleConstant() != -1) {
            //We are evaluating a predicate over a column and a double constant
            switch (simplePred.getPredCode()) {
            case PREDICATE_EQUAL:
                value1 = Double
                        .parseDouble(record.getField(simplePred.getColumn1(), StringValue.class).getValue());
                if (simplePred.getOperation1() != null)
                    value1 = simplePred.getOperation1().calculate(value1);
                return value1 == simplePred.getDoubleConstant();
            case PREDICATE_NOTEQUAL:
                value1 = Double
                        .parseDouble(record.getField(simplePred.getColumn1(), StringValue.class).getValue());
                if (simplePred.getOperation1() != null)
                    value1 = simplePred.getOperation1().calculate(value1);
                return value1 != simplePred.getDoubleConstant();
            case PREDICATE_SMALLEROREQUALTHAN:
                value1 = Double
                        .parseDouble(record.getField(simplePred.getColumn1(), StringValue.class).getValue());
                if (simplePred.getOperation1() != null)
                    value1 = simplePred.getOperation1().calculate(value1);
                return value1 <= simplePred.getDoubleConstant();
            case PREDICATE_SMALLERTHAN:
                value1 = Double
                        .parseDouble(record.getField(simplePred.getColumn1(), StringValue.class).getValue());
                if (simplePred.getOperation1() != null)
                    value1 = simplePred.getOperation1().calculate(value1);
                return value1 < simplePred.getDoubleConstant();
            case PREDICATE_GREATEROREQUALTHAN:
                value1 = Double
                        .parseDouble(record.getField(simplePred.getColumn1(), StringValue.class).getValue());
                if (simplePred.getOperation1() != null)
                    value1 = simplePred.getOperation1().calculate(value1);
                return value1 >= simplePred.getDoubleConstant();
            case PREDICATE_GREATERTHAN:
                value1 = Double
                        .parseDouble(record.getField(simplePred.getColumn1(), StringValue.class).getValue());
                if (simplePred.getOperation1() != null)
                    value1 = simplePred.getOperation1().calculate(value1);
                return value1 > simplePred.getDoubleConstant();
            default:
                throw new PAXQueryExecutionException(
                        "Predicate " + simplePred.toString() + " not implemented yet!");
            }
        }

        //We are evaluating a predicate over a column and a string constant
        switch (simplePred.getPredCode()) {
        case PREDICATE_EQUAL:
            if (simplePred.getStringConstant().startsWith("~")) {
                Pattern p = Pattern.compile(
                        "(^|\\s+|[^a-zA-Z0-9]+)" + simplePred.getStringConstant().substring(1,
                                simplePred.getStringConstant().length()) + "($|\\s+|[^a-zA-Z0-9]+)",
                        Pattern.MULTILINE);
                Matcher m = p.matcher(record.getField(simplePred.getColumn1(), StringValue.class));
                return m.find();
            }
            return record.getField(simplePred.getColumn1(), StringValue.class).toString()
                    .equals(simplePred.getStringConstant());
        case PREDICATE_NOTEQUAL:
            if (simplePred.getStringConstant().startsWith("~")) {
                Pattern p = Pattern.compile(
                        "(^|\\s+|[^a-zA-Z0-9]+)" + simplePred.getStringConstant().substring(1,
                                simplePred.getStringConstant().length()) + "($|\\s+|[^a-zA-Z0-9]+)",
                        Pattern.MULTILINE);
                Matcher m = p.matcher(record.getField(simplePred.getColumn1(), StringValue.class));
                return !m.find();
            }
            return !record.getField(simplePred.getColumn1(), StringValue.class).toString()
                    .equals(simplePred.getStringConstant());
        default:
            throw new PAXQueryExecutionException(
                    "Predicate " + simplePred.toString() + " not implemented yet!");
        }
    } catch (NumberFormatException nfe) {
        return false;
    }
}

From source file:wuit.crawler.CrawlerHtml.java

public String match(String content, String filter) {
    String val = "";
    try {/*ww  w  .j av  a2  s  . com*/
        Matcher m = Pattern.compile(filter, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE).matcher(content);
        while (m.find()) {
            val = m.group();
            break;
        }
    } catch (Exception e) {
        System.out.println("Composite Parse match " + e.getMessage());
    }
    return val;
}

From source file:org.apache.nifi.processors.standard.EvaluateRegularExpression.java

int getCompileFlags(ProcessContext context) {
    int flags = (context.getProperty(UNIX_LINES).asBoolean() ? Pattern.UNIX_LINES : 0)
            | (context.getProperty(CASE_INSENSITIVE).asBoolean() ? Pattern.CASE_INSENSITIVE : 0)
            | (context.getProperty(COMMENTS).asBoolean() ? Pattern.COMMENTS : 0)
            | (context.getProperty(MULTILINE).asBoolean() ? Pattern.MULTILINE : 0)
            | (context.getProperty(LITERAL).asBoolean() ? Pattern.LITERAL : 0)
            | (context.getProperty(DOTALL).asBoolean() ? Pattern.DOTALL : 0)
            | (context.getProperty(UNICODE_CASE).asBoolean() ? Pattern.UNICODE_CASE : 0)
            | (context.getProperty(CANON_EQ).asBoolean() ? Pattern.CANON_EQ : 0)
            | (context.getProperty(UNICODE_CHARACTER_CLASS).asBoolean() ? Pattern.UNICODE_CHARACTER_CLASS : 0);
    return flags;
}

From source file:org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.TrafficController.java

/**
 * Parses the current state looks for classids already in use
 *//*from   w  ww  .j av a  2s .c  om*/
private void reacquireContainerClasses(String state) {
    //At this point we already have already successfully passed
    //checkIfAlreadyBootstrapped() - so we know that at least the
    //root classes are in place.
    String tcClassesStr = state.substring(state.indexOf("class"));
    //one class per line - the results of the split will need to trimmed
    String[] tcClasses = Pattern.compile("$", Pattern.MULTILINE).split(tcClassesStr);
    Pattern tcClassPattern = Pattern.compile(String.format("class htb %d:(\\d+) .*", ROOT_QDISC_HANDLE));

    synchronized (classIdSet) {
        for (String tcClassSplit : tcClasses) {
            String tcClass = tcClassSplit.trim();

            if (!tcClass.isEmpty()) {
                Matcher classMatcher = tcClassPattern.matcher(tcClass);
                if (classMatcher.matches()) {
                    int classId = Integer.parseInt(classMatcher.group(1));
                    if (classId >= MIN_CONTAINER_CLASS_ID) {
                        classIdSet.set(classId - MIN_CONTAINER_CLASS_ID);
                        LOG.info("Reacquired container classid: " + classId);
                    }
                } else {
                    LOG.warn("Unable to match classid in string:" + tcClass);
                }
            }
        }
    }
}

From source file:fr.ign.cogit.geoxygene.appli.plugin.script.ScriptingPrimitiveRenderer.java

/**
 * Replace all 'include "YYY"' lines by the YYY file content
 * @param fileContent file content where to replace includes contents
 * @return preprocessed content// w w w . j a v a  2s.  co m
 * @throws RenderingException
 */
private static String preprocessInclude(final String filename, final String fileContent)
        throws RenderingException {
    if (fileContent == null) {
        return null;
    }
    try {
        Pattern includePattern = Pattern.compile("include\\s+[\\\"\\\'](.*)[\\\"\\\']", Pattern.MULTILINE);
        // Pattern includePattern = Pattern.compile("^\\s*include",
        // Pattern.MULTILINE);
        Matcher m = includePattern.matcher(fileContent);

        if (m.find() && m.groupCount() == 1) {
            return preprocessInclude(filename,
                    fileContent.replace(m.group(0), preprocessScriptingFile(new File(m.group(1)))));
        }
    } catch (PatternSyntaxException pse) {
        throw new RenderingException(pse);
    }
    return fileContent;
}

From source file:com.swordlord.jalapeno.datacontainer.DataContainer.java

/**
 * Filters the given rows using an complex filter.
 * /*w w w.j a  v a2  s  . co  m*/
 * @param <T>
 *            The row type
 * @param rows
 *            The rows to process
 * @param filter
 *            The complex filter
 * @param context
 *            The binding context or null
 * @param dt
 *            The table to which the rows belong
 * @return The filtered rows
 */
private static <T> List<T> complexFilter(List<T> rows, DataBindingContext context, DataTableBase dt,
        String filter) {
    // Example of a filter: ?NotIn(threatId,@ActiveThreat[0]:threatId)
    final Pattern pattern = Pattern.compile(
            "^(\\?)?([a-z]*)(\\(){1,1}([a-z]*)?(,){1,1}([(\\?)?a-z_0-9,:='%\\s@\\[\\]\\(\\)]*)?(\\)){1,1}$",
            Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    final Matcher matcher = pattern.matcher(filter);

    /*
     * The groups are as follows 1 - ! 2 - NotIn 3 - ( 4 - threatId 5 -
     * , 6 - @ActiveThreat[0]:threatId 7 - )
     */

    if (!matcher.find()) {
        LOG.info("Parser can't parse filter: " + filter);
        return rows;
    }

    if (matcher.groupCount() != 7) {
        LOG.error("Wrong group count during parsing of filter: " + filter);
        return rows;
    }

    final String strCommand = matcher.group(2);
    final String strBoundField = matcher.group(4).replace(":", ".");
    final String strBindingMember = matcher.group(6).replace(":", ".");

    final DataBindingMember bm = new DataBindingMember(strBindingMember);

    // re-use the DataBindingContext when there is one
    // this is needed so that all currentRow informations are correct
    // within a filter
    final DataBindingManager dbm;
    if (context != null) {
        dbm = context.getDataBindingManager(bm);
    } else {
        dbm = new DataBindingManager(dt.getDataContainer(), bm);
    }

    // get all to-be-filtered records as field because the expression
    // filters on one single field and does no lookup
    final List<String> fieldsFilter = new ArrayList<String>();
    for (DataRowBase row : dbm.getRows(bm)) {
        if (row.getPersistenceState() != PersistenceState.DELETED) {
            final String strFieldName = bm.getDataBindingFieldName();
            if (strFieldName == null || strFieldName.length() == 0) {
                LOG.error("There must be something wrong with your filter. Field is empty: " + filter);
            } else {
                fieldsFilter.add(row.getPropertyAsStringForce(strFieldName));
            }
        }
    }

    // Create the expression according to the binding information
    if (strCommand.equalsIgnoreCase("in")) {
        final Expression exp = ExpressionFactory.inExp(strBoundField, fieldsFilter);
        return new ArrayList<T>(exp.filterObjects(rows));
    } else if (strCommand.equalsIgnoreCase("notin")) {
        final Expression exp = ExpressionFactory.notInExp(strBoundField, fieldsFilter);
        return new ArrayList<T>(exp.filterObjects(rows));
    } else {
        LOG.warn("Unknown filter command: " + strCommand);
        return rows;
    }
}