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:morphy.utils.RegExUtils.java

public static Pattern getPattern(String regularExpression) {
    return Pattern.compile(regularExpression, Pattern.MULTILINE | Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
}

From source file:Main.java

public static int getLengthOfLongestWord(String string) {
    int longestWordLength = 0;
    Matcher m = Pattern.compile("\\s*(\\S+)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE).matcher(string);
    while (m.find()) {
        longestWordLength = Math.max(longestWordLength, m.group(1).length());
    }/*from w w w .ja va2 s.  c  o m*/
    return longestWordLength;
}

From source file:org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil.java

public static String addAsterixAtEachLineStart(final String input) {
    String s = Pattern.compile("^", Pattern.MULTILINE).matcher(input).replaceAll("* ");
    // remove trailing spaces
    s = Pattern.compile("\\s+$", Pattern.MULTILINE).matcher(s).replaceAll("");
    s = ensureEndsWithSingleNewLine(s);//from w ww .  ja  va 2  s .  c  o m
    return s;
}

From source file:org.opennms.gizmo.k8s.portforward.KubeCtlPortForwardingStrategy.java

protected static Integer getLocalPortFromOutput(String out) {
    Pattern p = Pattern.compile(" (.*):(\\d+) -> (\\d+)", Pattern.MULTILINE);
    Matcher m = p.matcher(out);/*from   w ww. ja  va2 s .  co  m*/
    if (m.find()) {
        return Integer.valueOf(m.group(2));
    }
    return null;
}

From source file:bkampfbot.state.Opponent.java

public final static Opponent getById(String id) throws NotFound {
    Opponent o = new Opponent();

    String profilePage = Utils.getString("characters/profile/" + id);

    int pos = profilePage.indexOf("href=\"/fights/start/");
    if (pos == -1) {
        throw new NotFound();
    }/* ww w .  j a  v  a2s.com*/

    String page = profilePage.substring(pos);
    page = page.substring(0, page.indexOf("<img"));

    Pattern p = Pattern.compile("/fights/start/([0-9]+)\"", Pattern.MULTILINE);
    Matcher m = p.matcher(page);

    if (!m.find()) {
        throw new NotFound();
    }

    o.setAttack("/fights/start/" + m.group(1));

    pos = profilePage.indexOf("<center><b>");
    if (pos == -1) {
        throw new NotFound();
    }

    page = profilePage.substring(pos + "<center><b>".length());
    page = page.substring(0, page.indexOf("</b></center>")).trim();

    o.setName(page);

    return o;
}

From source file:org.squale.welcom.struts.lazyLoading.WLazyUtil.java

/**
 * recherche les parametres dans un tag/*from  w  ww .java 2  s.  c o m*/
 * 
 * @param s chaine contenant le script du tag
 * @return une hashtable contenant les paramtres et leur valeur.
 */
private static Hashtable searchParameter(final String s) {
    final Hashtable parameters = new Hashtable();

    final Pattern pattern = Pattern.compile("(name|type|value|checked)\\s*=\\s*([\"\'])",
            Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    final Matcher matcher = pattern.matcher(s);
    int pos = 0;

    while (matcher.find(pos)) {
        final String name = matcher.group(1);
        char charDelimiter = ' ';
        if (!GenericValidator.isBlankOrNull(matcher.group(2))) {
            charDelimiter = matcher.group(2).charAt(0);
        }

        final int posStart = matcher.end(2);
        final int posEnd = s.indexOf(charDelimiter, posStart);

        final String value = s.substring(posStart, posEnd);

        parameters.put(name.toLowerCase(), charDelimiter + value + charDelimiter);

        pos = matcher.end(2);
    }

    return parameters;
}

From source file:de.ist.clonto.webwiki.InfoboxParser.java

public List<Information> parse(String text) {
    String pagetext = replaceHTMLComments(text);
    List<Information> setlist = new ArrayList<Information>();

    Pattern pattern = Pattern.compile("\\{\\{\\s*infobox",
            Pattern.MULTILINE | Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
    Matcher matcher = pattern.matcher(pagetext);
    while (matcher.find()) {
        int begin = matcher.start();
        int bracketnr = 2;
        int end = begin + matcher.group().length();
        while (end < pagetext.length()) {
            switch (pagetext.charAt(end)) {
            case '}':
                bracketnr--;//from   w  ww  .  j  av a2s  .  co m
                break;
            case '{':
                bracketnr++;
                break;
            }
            if (bracketnr == 0) {
                break;
            }
            end++;
        }
        String infobox = pagetext.substring(begin, end);
        Information info = parseSet(infobox);
        setlist.add(info);
    }

    return setlist;
}

From source file:org.openremote.beehive.utils.StringUtil.java

/**
 * Parses the <code>Model</code> name in a comment
 * //www  .j  av  a  2s.com
 * @param comment
 *           the comment to parse
 * @return <code>Model</code> name
 */
public static String parseModelNameInComment(String comment) {
    String regexpLine = "^\\s*#\\s*(model|model\\s*no\\.\\s*of\\s*remote\\s*control)\\s*:.*?$";
    Pattern patLine = Pattern.compile(regexpLine, Pattern.MULTILINE);
    Matcher m = patLine.matcher(comment);
    String targetLine = "";
    while (m.find()) {
        targetLine = m.group(0);
        break;
    }
    String name = targetLine.substring(targetLine.indexOf(":") + 1).trim();
    int braceIndex = name.indexOf('(');
    if (braceIndex != -1) {
        name = name.substring(0, name.indexOf('(')).trim();
    }
    return name.replace(" ", "_");
}

From source file:com.wavemaker.tools.project.CloudFoundryStudioConfiguration.java

/**
 * Gets the current VersionInfo from the VERSION file.
 *//*from ww  w  .j  a  va 2 s .c o  m*/
public static VersionInfo getCurrentVersionInfo() throws IOException {

    String versionFileString = getCurrentVersionInfoString();

    final Pattern p = Pattern.compile("^Version: (.*)$", Pattern.MULTILINE);
    Matcher m = p.matcher(versionFileString);
    if (!m.find()) {
        throw new WMRuntimeException("bad version string: " + versionFileString);
    }

    return new VersionInfo(m.group(1));
}

From source file:com.github.koraktor.steamcondenser.community.SteamGame.java

/**
 * Checks if a game is up-to-date by reading information from a
 * <code>steam.inf</code> file and comparing it using the Web API
 *
 * @param path The file system path of the `steam.inf` file
 * @return <code>true</code> if the game is up-to-date
 * @throws IOException if the steam.inf cannot be read
 * @throws JSONException if the JSON data is malformed
 * @throws SteamCondenserException if the given steam.inf is invalid or
 *         the Web API request fails/*from w  w  w  . ja v  a 2s . c  o m*/
 */
public static boolean checkSteamInf(String path) throws IOException, JSONException, SteamCondenserException {
    BufferedReader steamInf = new BufferedReader(new FileReader(path));
    String steamInfContents = "";

    while (steamInf.ready()) {
        steamInfContents += steamInf.readLine() + "\n";
    }
    steamInf.close();

    Pattern appIdPattern = Pattern.compile("^\\s*appID=(\\d+)\\s*$",
            Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    Matcher appIdMatcher = appIdPattern.matcher(steamInfContents);
    Pattern versionPattern = Pattern.compile("^\\s*PatchVersion=([\\d\\.]+)\\s*$",
            Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    Matcher versionMatcher = versionPattern.matcher(steamInfContents);

    if (!(appIdMatcher.find() && versionMatcher.find())) {
        throw new SteamCondenserException("The steam.inf file at \"" + path + "\" is invalid.");
    }

    int appId = Integer.parseInt(appIdMatcher.group(1));
    int version = Integer.parseInt(versionMatcher.group(1).replace(".", ""));

    return isUpToDate(appId, version);
}