Example usage for java.util.regex Matcher find

List of usage examples for java.util.regex Matcher find

Introduction

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

Prototype

public boolean find() 

Source Link

Document

Attempts to find the next subsequence of the input sequence that matches the pattern.

Usage

From source file:Main.java

public static String constructNextPageBookSearchUrl(String currentBookSearchUrl, int currentPage) {
    final Matcher matcher = NEXT_PAGE_URL_PATTERN.matcher(currentBookSearchUrl);
    if (matcher.find()) {
        currentPage = Integer.parseInt(matcher.group(1));
        currentPage++;//from   w  w w  .j  a  va2s .co  m

        String cleanedBookSearchUrl = currentBookSearchUrl.replaceAll("(\\d+)$", "");
        return cleanedBookSearchUrl + currentPage;
    } else {
        currentPage++;
        return currentBookSearchUrl + "/page/" + currentPage;
    }
}

From source file:Main.java

/**
 * Get parameter value from SDP parameters string with parameter-value
 * format 'key1=value1; ... keyN=valueN'
 * /*  w  w  w. j av a2s  .c o  m*/
 * @param paramKey parameter name
 * @param params parameters string
 * @return if parameter exists return {@link String} with value, otherwise
 *         return <code>null</code>
 */
public static String getParameterValue(String paramKey, String params) {
    String value = null;
    if (params != null && params.length() > 0) {
        try {
            java.util.regex.Pattern p = java.util.regex.Pattern.compile("(?<=" + paramKey + "=).*?(?=;|$)");
            java.util.regex.Matcher m = p.matcher(params);
            if (m.find()) {
                value = m.group(0);
            }
        } catch (java.util.regex.PatternSyntaxException ex) {
        }
    }
    return value;
}

From source file:Main.java

public static boolean likeFUC(String str, String pattenStr) {
    boolean result = false;
    if (str != null && !str.equals("")) {
        Matcher m = Pattern.compile(pattenStr, Pattern.CASE_INSENSITIVE).matcher(str);
        while (m.find()) {
            result = true;/*from   www  .j  a v  a  2  s.  co  m*/
        }
    }
    return result;
}

From source file:Main.java

/**
 * Remove version information from given objid.
 *
 * @param objid The objid./*from   w  w  w  .  ja  v  a  2 s  . co m*/
 * @return The objid without version information.
 */
public static String getObjidWithoutVersion(final String objid) {

    String result = objid;
    final Matcher m = PATTERN_ID_WITHOUT_VERSION.matcher(objid);
    if (m.find()) {
        result = m.group(1);
    }
    return result;
}

From source file:Main.java

/**
 * Extract default values of variables defined in the given string.
 * Default values are used to populate the variableDefs map.  Variables
 * already defined in this map will NOT be modified.
 *
 * @param string string to extract default values from.
 * @param variableDefs map which default values will be added to.
 *//*from w  ww .j a v  a2  s .com*/
public static void extractVariableDefaultsFromString(String string, Map<String, String> variableDefs) {
    Matcher variableMatcher = variablePattern.matcher(string);
    while (variableMatcher.find()) {
        String varString = variableMatcher.group(1);

        int eqIdx = varString.indexOf("=");

        if (eqIdx > -1) {
            String varName = varString.substring(0, eqIdx).trim();

            if (!variableDefs.containsKey(varName))
                variableDefs.put(varName, varString.substring(eqIdx + 1, varString.length()));
        }
    }
}

From source file:Main.java

public static int getCharacterPosition(String string, int next, String sub) {
    Matcher slashMatcher = Pattern.compile(sub).matcher(string);
    int index = 0;
    while (slashMatcher.find()) {
        index++;//from  ww  w  .j a v a 2  s.  com
        if (index == next)
            break;
    }
    return slashMatcher.start();
}

From source file:Main.java

public static String fixTagEndings(String body) {
    String newBody = body;// w w  w.  j av a  2s .  c o m
    Matcher matcher = ENDTAG_AFTER_NEWLINE_PATTERN.matcher(body);
    while (matcher.find()) {
        String endTag = matcher.group(1);
        newBody = newBody.replaceFirst("\n" + endTag, endTag + "\n");
        matcher = ENDTAG_AFTER_NEWLINE_PATTERN.matcher(newBody);
    }
    return newBody;
}

From source file:Main.java

public static String infoParser(int idx, String re, String[] contents) {
    if (idx < contents.length && idx >= 0) {
        String content = contents[idx];
        if (!TextUtils.isEmpty(re)) {
            Matcher matcher = Pattern.compile(re).matcher(content);
            if (matcher.find()) {
                content = matcher.group();
            }//from   w  w  w . j  a  v  a2 s.c om
        }
        return content;
    } else {
        return "";
    }
}

From source file:com.krminc.phr.api.converter.util.ConverterUtils.java

public static final Boolean isValidMask(String mask) {
    mask = prepareInput(mask);//from  w  ww.ja va 2s . c  o m
    //mask is binary string
    final String MASK_REGEX = "^[01]+$";
    Pattern pattern = Pattern.compile(MASK_REGEX);
    Matcher matcher = pattern.matcher(mask);
    if (matcher.find()) {
        return true;
    }
    return false;
}

From source file:Main.java

/**
 * Apply a regex on a String// w  w  w  .  java 2s .  c  o  m
 * 
 * @param stringToParse
 * @param regex
 * @return The result of the regex
 * @throws Exception
 */
public static String applyRegex(String stringToParse, String regex) throws Exception {
    // String issue = execute(issueRestUrl);
    /**
     * Qui fonctionnent : - (?<=<[\\/?]?)\\w+(?::\\w+)? : retourne le tag - classname=\"(.*?)\" : retourne l'attribut et se valeur
     */
    // System.out.println("Tested string : " + stringToParse);
    // String regex = "classname=\"(.*?)\"";
    // .*\"status\":\\{.*?\"name\":\"(.*?)\".*?\\}.*
    // .?[a-z]*\"
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(stringToParse);

    if (m.find()) {
        return m.group();
    } else {
        return "";
    }

}