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.echocat.jomon.runtime.jaxb.PatternAdapter.java

@Nonnegative
protected int toFlags(@Nonnull String flagsAsString) {
    final Set<Character> flagsAsCharacters = newHashSet(toObject(flagsAsString.toCharArray()));
    int flags = 0;
    if (flagsAsCharacters.contains('i')) {
        flags |= Pattern.CASE_INSENSITIVE;
    }//ww w . j  a va2 s  . c  o m
    if (flagsAsCharacters.contains('m')) {
        flags |= Pattern.MULTILINE;
    }
    if (flagsAsCharacters.contains('s')) {
        flags |= Pattern.DOTALL;
    }
    if (flagsAsCharacters.contains('x')) {
        flags |= Pattern.COMMENTS;
    }
    return flags;
}

From source file:it.test.CoverageTrackingTest.java

private String extractSuccessfulTestId(String json) {
    Matcher jsonObjectMatcher = Pattern.compile(".*\\{((.*?)success(.*?))\\}.*", Pattern.MULTILINE)
            .matcher(json);//  www.j  a v a 2 s.  c om
    jsonObjectMatcher.find();

    Matcher idMatcher = Pattern.compile(".*\"id\"\\s*?:\\s*?\"(\\S*?)\".*", Pattern.MULTILINE)
            .matcher(jsonObjectMatcher.group(1));
    return idMatcher.find() ? idMatcher.group(1) : "";
}

From source file:io.wcm.maven.plugins.contentpackage.httpaction.PackageManagerHtmlMessageCall.java

@Override
public String execute() throws MojoExecutionException {
    if (log.isDebugEnabled()) {
        log.debug("Call URL: " + method.getURI());
    }// w  ww .  jav a2  s.  com

    try (CloseableHttpResponse response = httpClient.execute(method)) {
        String responseString = EntityUtils.toString(response.getEntity());

        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {

            // debug output whole xml
            if (log.isDebugEnabled()) {
                log.debug("CRX Package Manager Response:\n" + responseString);
            }

            // remove all HTML tags and special conctent
            final Pattern HTML_STYLE = Pattern.compile("<style[^<>]*>[^<>]*</style>",
                    Pattern.MULTILINE | Pattern.DOTALL);
            final Pattern HTML_JAVASCRIPT = Pattern.compile("<script[^<>]*>[^<>]*</script>",
                    Pattern.MULTILINE | Pattern.DOTALL);
            final Pattern HTML_ANYTAG = Pattern.compile("<[^<>]*>");

            responseString = HTML_STYLE.matcher(responseString).replaceAll("");
            responseString = HTML_JAVASCRIPT.matcher(responseString).replaceAll("");
            responseString = HTML_ANYTAG.matcher(responseString).replaceAll("");
            responseString = StringUtils.replace(responseString, "&nbsp;", " ");

            return responseString;
        } else {
            throw new MojoExecutionException("Failure:\n" + responseString);
        }

    } catch (IOException ex) {
        throw new MojoExecutionException("Http method failed.", ex);
    }
}

From source file:org.freaknet.gtrends.api.GoogleTrendsCsvParser.java

/**
 * Gets the specified section from the CSV.
 *
 * @param section Section of the CSV to retrieve
 * @param header If the section has a header. If <code>true</code> the first
 * line will be skipped.//from  w w  w.j  av a2 s.c  o  m
 * @return content The content of the section
 */
public String getSectionAsString(String section, boolean header) {
    String ret = null;
    Logger.getLogger(GoogleConfigurator.getLoggerPrefix()).log(Level.FINE, "Parsing CSV for section: {0}",
            section);

    Pattern startSectionPattern = Pattern.compile("^" + section + ".*$", Pattern.MULTILINE);
    Matcher matcher = startSectionPattern.matcher(_csv);

    if (matcher.find()) {
        ret = _csv.subSequence(matcher.start(), _csv.length()).toString();

        int end = ret.length();

        Pattern endSectionPattern = Pattern.compile("\n\n", Pattern.MULTILINE);
        matcher = endSectionPattern.matcher(ret);
        if (matcher.find()) {
            end = matcher.start();
        }

        ret = ret.subSequence(0, end).toString().substring(ret.indexOf('\n') + 1);

        if (header) {
            ret = ret.substring(ret.indexOf('\n') + 1);
        }
    } else {
        Logger.getLogger(GoogleConfigurator.getLoggerPrefix()).log(Level.WARNING,
                "Writing the full CSV file. Section not found: #{0}", section);
        return "";
    }

    return ret;
}

From source file:org.limy.eclipse.qalab.outline.jdepend.JDependSvgParser.java

private String getHtmlContents(IFile file) {
    try {/*from w w  w  .  j a  v  a 2 s.c  o m*/
        String contents = IOUtils.toString(file.getContents(), file.getCharset());
        return Pattern.compile("<.*>", Pattern.MULTILINE).matcher(contents).replaceAll("").trim();
    } catch (IOException e) {
        return null;
    } catch (CoreException e) {
        return null;
    }
}

From source file:com.thoughtworks.go.domain.materials.perforce.P4OutputParser.java

Modification modificationFromDescription(String output, ConsoleResult result) throws P4OutputParseException {
    String[] parts = StringUtils.splitByWholeSeparator(output, SEPARATOR);
    Pattern pattern = Pattern.compile(DESCRIBE_OUTPUT_PATTERN, Pattern.MULTILINE);
    Matcher matcher = pattern.matcher(parts[0]);
    if (matcher.find()) {
        Modification modification = new Modification();
        parseFistline(modification, matcher.group(1), result);
        parseComment(matcher, modification);
        parseAffectedFiles(parts, modification);
        return modification;
    }//w  w w .  j ava 2  s  .  c om
    throw new P4OutputParseException("Could not parse P4 description: " + output);
}

From source file:Normalization.TextNormalization.java

public String removeMentionsFromString(String content) {

    String utf8tweet = "";
    try {//from w w w  .j  ava 2 s  .co  m
        byte[] utf8Bytes = content.getBytes("UTF-8");

        utf8tweet = new String(utf8Bytes, "UTF-8");
    } catch (UnsupportedEncodingException e) {
    }

    final String regex = "[@]\\w+";
    final Pattern unicodeOutliers = Pattern.compile(regex,
            Pattern.MULTILINE | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);

    Matcher unicodeOutlierMatcher = unicodeOutliers.matcher(utf8tweet);
    utf8tweet = unicodeOutlierMatcher.replaceAll("");
    return utf8tweet.replace("#", "");
}

From source file:com.atlassian.webdriver.greenhopper.page.admin.GreenHopperLicenseDetailsPage.java

private String extractExpiryDate(String licenseTypeStr) {
    licenseTypeStr = licenseTypeStr.replaceAll("\\n", "");

    Pattern p = Pattern.compile("(\\d{2}/[A-Za-z]{3}/\\d{2})", Pattern.MULTILINE);
    Matcher m = p.matcher(licenseTypeStr);

    String expiryStr = null;//from   w ww . ja  va 2  s .  co  m

    if (m.find()) {
        expiryStr = m.group(1);
    }

    return expiryStr;
}

From source file:nz.net.orcon.kanban.automation.actions.RegexAction.java

public String extract(String text, String expressionString, int match, int group, String options)
        throws IOException {

    if (text == null) {
        text = "";
    }/*from   w  ww  .  j  a  v  a 2s .  co  m*/

    if (expressionString == null) {
        throw new IllegalArgumentException(
                "No Regular Expression has been provided to carry out this operation.");
    }

    int optionsInEffect = 0;
    if (options != null) {
        for (String option : options.toUpperCase().split("\\|")) {
            optionsInEffect |= (option.equals("CANON_EQ")) ? Pattern.CANON_EQ
                    : (option.equals("CASE_INSENSITIVE")) ? Pattern.CASE_INSENSITIVE
                            : (option.equals("COMMENTS")) ? Pattern.COMMENTS
                                    : (option.equals("DOTALL")) ? Pattern.DOTALL
                                            : (option.equals("LITERAL")) ? Pattern.LITERAL
                                                    : (option.equals("MULTILINE")) ? Pattern.MULTILINE
                                                            : (option.equals("UNICODE_CASE"))
                                                                    ? Pattern.UNICODE_CASE
                                                                    : (option.equals("UNIX_LINES"))
                                                                            ? Pattern.UNIX_LINES
                                                                            : 0;
        }
    }

    Pattern expression = Pattern.compile(expressionString, optionsInEffect);
    Matcher matches = expression.matcher(text);

    int matchIndex = 1;
    while (matches.find()) {
        for (int groupIndex = 0; matches.groupCount() + 1 > groupIndex; groupIndex++) {
            if (matchIndex == match && groupIndex == group) {
                return matches.group(groupIndex);
            }
        }
        matchIndex++;
    }

    return "";
}

From source file:de.csw.linkgenerator.CSWLinksetRenderer.java

public CSWLinksetRenderer() {
    try {/*www.j a  v  a2s. com*/
        InputStream is = CSWLinksetRenderer.class.getResourceAsStream(FILENAME_CSWLINK_POPUP_HTML);
        if (is == null) {
            log.error("Unable to read HTML template of the CSW popup");
            return;
        }
        cswLinkPopupHTML = IOUtils.toString(is);

        // strip empty lines
        Pattern emptyLinePattern = Pattern.compile("$\n^\\s*$", Pattern.MULTILINE);
        cswLinkPopupHTML = emptyLinePattern.matcher(cswLinkPopupHTML).replaceAll("");
        cswLinkPopupHTML = cswLinkPopupHTML.replace("[", "&#91;");
        cswLinkPopupHTML = cswLinkPopupHTML.replace("]", "&#93;");
    } catch (IOException e) {
        log.error("Could not read " + FILENAME_CSWLINK_POPUP_HTML, e);
    }
}