Example usage for java.util.regex Pattern DOTALL

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

Introduction

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

Prototype

int DOTALL

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

Click Source Link

Document

Enables dotall mode.

Usage

From source file:application.Crawler.java

private void extractLinkAndTitle(String text) {

    link = null;// w  ww. j a v  a2s.  c o m
    title = null;
    Pattern p = Pattern.compile(
            "<div class=\"productNameAndPromotions\">.*<a href=\"(.*)\" >(.*)<img src=\".*\">", Pattern.DOTALL);
    Matcher m = p.matcher(text);
    while (m.find()) {
        link = m.group(1).trim();
        title = m.group(2).trim();
    }

}

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   w ww.ja v a 2s  .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.asual.summer.core.faces.FacesResponseWriter.java

private void printTextIfNecessary(boolean end) throws IOException {
    String textStr = textWriter.toString();
    if (StringUtils.hasText(textStr)) {
        String name = nodeDepth[depth];
        textStr = textStr.replaceAll("\t", INDENT);
        if (ComponentUtils.isStyleOrScript(name)) {
            textStr = Pattern.compile("^\\s{" + calculateIndent(textStr) + "}", Pattern.MULTILINE)
                    .matcher(textStr).replaceAll(getIndent(depth)).trim();
        }// w  w  w .j a v a 2 s  .  c o m
        if (block.contains(name) && !pre.contains(name)) {
            Matcher m = Pattern.compile("^( *\\n)+.*", Pattern.DOTALL).matcher(textStr);
            if (m.matches()) {
                textStr = m.replaceFirst("$1") + getIndent(depth) + StringUtils.trimLeadingWhitespace(textStr);
            } else if (start) {
                textStr = "\n" + getIndent(depth) + StringUtils.trimLeadingWhitespace(textStr);
            }
            m = Pattern.compile(".*(\\n)+ *$", Pattern.DOTALL).matcher(textStr);
            if (m.matches()) {
                textStr = StringUtils.trimTrailingWhitespace(textStr) + m.replaceFirst("$1") + getIndent(depth);
            }
        }
        if (end) {
            textStr = StringUtils.trimTrailingWhitespace(textStr);
        }
        writer.write(textStr);
        textWriter.getBuffer().setLength(0);
        start = false;

        nodeDepth[depth + 1] = null;
        for (int i = 0; i < depth + 1; i++) {
            nodeDepthContent[i] = true;
        }
    }
}

From source file:net.sourceforge.jwbf.actions.mw.queries.GetBacklinkTitles.java

/**
 * gets the information about a follow-up page from a provided api response.
 * If there is one, the information for the next page parameter is 
 * added to the nextPageInfo field.//from  w w  w .j  a v  a 2s . co m
 *   
 * @param s   text for parsing
 */
protected void parseHasMore(final String s) {

    // get the blcontinue-value

    Pattern p = Pattern.compile(
            "<query-continue>.*?" + "<backlinks *blcontinue=\"([^\"]*)\" */>" + ".*?</query-continue>",
            Pattern.DOTALL | Pattern.MULTILINE);

    Matcher m = p.matcher(s);

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

}

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 www . ja v  a2  s. c  o 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:net.sourceforge.jwbf.actions.mw.queries.GetAllPageTitles.java

/**
 * gets the information about a follow-up page from a provided api response.
 * If there is one, a new request is added to msgs by calling generateRequest.
 *   /*w  w  w.j  av  a 2 s . c  om*/
 * @param s   text for parsing
 */
protected void parseHasMore(final String s) {

    // get the blcontinue-value

    Pattern p = Pattern.compile(
            "<query-continue>.*?" + "<allpages *apfrom=\"([^\"]*)\" */>" + ".*?</query-continue>",
            Pattern.DOTALL | Pattern.MULTILINE);

    Matcher m = p.matcher(s);

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

}

From source file:nya.miku.wishmaster.http.recaptcha.Recaptcha2.java

/**
 *  /*from   w w w  .  j a v  a2  s. com*/
 * @param answer   
 * @param task ?? 
 * @return  ? ?  - ?,       "g-recaptcha-response"
 * @throws RecaptchaException ?  ?  
 */
public String checkCaptcha(String answer, CancellableTask task) throws RecaptchaException {
    try {
        HttpEntity postEntity = ExtendedMultipartBuilder.create().addString("c", this.challenge)
                .addString("response", answer).build();
        String response = HttpStreamer.getInstance().getStringFromUrl(
                scheme + RECAPTCHA_FALLBACK_URL + publicKey,
                HttpRequestModel.builder().setPOST(postEntity).build(), httpClient, null, task, false);

        String hash = "";
        Matcher matcher = Pattern
                .compile("fbc-verification-token(?:.*?)<textarea[^>]*>([^<]*)<", Pattern.DOTALL)
                .matcher(response);
        if (matcher.find())
            hash = matcher.group(1);

        if (hash.length() > 0) {
            return hash;
        } else {
            throw new RecaptchaException("RECAPTCHA: probably the incorrect answer (hash is empty)");
        }
    } catch (Exception e) {
        if (e instanceof RecaptchaException) {
            throw (RecaptchaException) e;
        } else {
            throw new RecaptchaException(e);
        }
    }
}

From source file:de.micromata.tpsb.doc.parser.JavaDocUtil.java

/**
 * Parst einen JavaDoc Tag/*from w w w  .jav a 2  s .  c  o m*/
 * 
 * @param tag der Tag-String
 * @param tagMap die zu befllende Tag-Map
 */
private static void parseTag(String tag, Map<String, List<Pair<String, String>>> tagMap) {
    final String TUPEL_PATTERN = "^(%s)(.*)$";
    final String TRIPEL_PATTERN = "^(@\\S*)\\s(\\S*)(.*)$";
    int idx = StringUtils.indexOf(tag, " ");
    String tagName = StringUtils.substring(tag, 0, idx);

    String pattern = tupelTags.contains(tagName) ? TUPEL_PATTERN : TRIPEL_PATTERN;
    Pattern p = Pattern.compile(String.format(pattern, tagName), Pattern.DOTALL);
    Matcher matcher = p.matcher(tag);
    String key = null;
    String val = null;
    if (matcher.matches() == true) {
        switch (matcher.groupCount()) {
        case 2:
            val = matcher.group(2).trim();
            break;
        case 3:
            key = matcher.group(2).trim();
            val = matcher.group(3).trim();
            break;
        default:
            System.out.println("Kein Match");
        }
        if (tagMap.get(tagName) == null) {
            tagMap.put(tagName, new ArrayList<Pair<String, String>>());
        }
        tagMap.get(tagName).add(Pair.make(key, val));
    }
}

From source file:com.googlecode.promnetpp.main.Main.java

private static void preprocessSourceCode() {
    StringBuilder sourceCodeAsBuilder = new StringBuilder(sourceCode);
    String commentRegex = "/[*].*?[*]/";
    Pattern commentPattern = Pattern.compile(commentRegex, Pattern.DOTALL);
    Matcher commentMatcher = commentPattern.matcher(sourceCodeAsBuilder);
    while (commentMatcher.find()) {
        String comment = commentMatcher.group().replace("/*", "").replace("*/", "").trim();
        boolean isAnnotatedComment = comment.startsWith("@");
        if (!isAnnotatedComment) {
            //Remove the comment and reset the matcher
            sourceCodeAsBuilder.delete(commentMatcher.start(), commentMatcher.end());
            commentMatcher = commentPattern.matcher(sourceCodeAsBuilder);
        }/*  ww  w  .  j a va 2 s  . c o  m*/
    }
    sourceCode = sourceCodeAsBuilder.toString();
}

From source file:org.ms123.common.docbook.BaseBuilder.java

private Object[] getLineNumberFromMsg(String msg) {
    Pattern p = Pattern.compile(".*SimpleTemplateScript\\d{1,5}.groovy: (\\d{1,5}):(.*)", Pattern.DOTALL);
    Matcher m = p.matcher(msg);/*from  w  w w.j  a  va 2s  .co m*/
    Object[] ret = new Object[2];
    if (m.find()) {
        ret[0] = m.group(1);
        ret[1] = m.group(2);
        return ret;
    }
    return null;
}