Example usage for java.util.regex Matcher group

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

Introduction

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

Prototype

public String group(String name) 

Source Link

Document

Returns the input subsequence captured by the given named-capturing group during the previous match operation.

Usage

From source file:com.gistlabs.mechanize.document.html.JsoupDataUtil.java

/**
 * Parse out a charset from a content type header.
 * @param header e.g. "text/html; charset=EUC-JP"
 * @return "EUC-JP", or null if not found. Charset is trimmed and uppercased.
 *//*from   ww  w.  j  av  a2  s.  c o  m*/
public static String getCharsetFromContentType(Header header) {
    if (header == null || header.getValue() == null || "".equals(header.getValue()))
        return null;
    Matcher m = charsetPattern.matcher(header.getValue());
    if (m.find()) {
        return m.group(1).trim().toUpperCase();
    }
    return null;
}

From source file:com.mastfrog.acteur.util.BasicCredentials.java

public static BasicCredentials parse(String header) {
    Matcher m = HEADER.matcher(header);
    if (m.matches()) {
        String base64 = m.group(1);
        //            byte[] decoded = Base64.getDecoder().decode(base64);
        //            String s = new String(decoded, UTF_8);
        byte[] bytes = base64.getBytes(UTF_8);
        if (Base64.isArrayByteBase64(bytes)) {
            bytes = Base64.decodeBase64(bytes);
        }/*  www . ja v a  2s  .  c om*/
        String s = new String(bytes, US_ASCII);
        m = UNPW.matcher(s);
        if (m.matches()) {
            String username = m.group(1);
            String password = m.group(2);
            return new BasicCredentials(username, password);
        }
    }
    return null;
}

From source file:cop.raml.utils.javadoc.tags.TagLink.java

private static String getLinkClassName(String doc) {
    if (StringUtils.isBlank(doc))
        return null;

    Matcher matcher = PATTERN.matcher(doc);
    return matcher.find() ? matcher.group("cls") : null;
}

From source file:cop.raml.utils.javadoc.tags.TagLink.java

private static String getLinkParamName(String doc) {
    if (StringUtils.isBlank(doc))
        return null;

    Matcher matcher = PATTERN.matcher(doc);
    return matcher.find() ? matcher.group("par") : null;
}

From source file:com.uimirror.core.framework.rest.util.WebUtil.java

/**
 * Find a Domain name from the URL// w  w w  . jav a 2  s .co  m
 * i.e for http://account.uimirror.com/abc it will extract http://account.uimirror.com
 * @param url which will be parsed
 * @return domain from the url
 */
public static String getURLDomain(String url) {
    Matcher m = URL_PATTERN.matcher(url);
    if (m.find())
        return m.group(0);
    return null;
}

From source file:Main.java

private static HashMap<String, String> parseContent(String src) {
    HashMap<String, String> map = new HashMap<String, String>();
    String patternStr = "http://(.*)\\?chat_id=[-]?(\\d+)&chat_name=(.+)";

    Pattern p = Pattern.compile(patternStr);
    Matcher m = p.matcher(src);
    if (!m.find()) {
        return null;
    } else if (m.groupCount() == 3) {
        map.put("chat_id", m.group(2));
        map.put("chat_name", m.group(3));
        return map;
    }// www . j  a  v  a 2 s.  c om

    return null;
}

From source file:Main.java

/**
 * Handle range form like x3-12/* w w w. j  a  va2  s . co  m*/
 *
 * @param rs Range List
 * @param r Range Token
 */
private static boolean range0(List<String> rs, String r) {
    Matcher matcher = range0Pattern.matcher(r);
    if (!matcher.matches())
        return false;

    String prefix = matcher.group(1);
    int begin = Integer.parseInt(matcher.group(2));
    int end = Integer.parseInt(matcher.group(3));
    for (int i = begin; i <= end; ++i) {
        rs.add(prefix + i);
    }
    return true;
}

From source file:net.mikaboshi.intra_mart.tools.log_stats.util.LogStringUtil.java

/**
 * URL?????/*from www  .  j  av a2s  . c  o m*/
 * @param url
 * @return
 */
public static String truncateUrl(String url) {

    if (url == null) {
        return StringUtils.EMPTY;
    }

    Matcher matcher = TRUNCATE_URL_PATTERN.matcher(url);

    if (matcher.matches()) {
        return matcher.group(1);
    } else {
        return url;
    }
}

From source file:Main.java

public static float getTotalRAM() {
    RandomAccessFile reader = null;
    String load = null;/*from w w w  .j  av  a2 s  . c o  m*/
    DecimalFormat twoDecimalForm = new DecimalFormat("#.##");
    double totRam = 0;
    float lastValue = 0;
    try {
        reader = new RandomAccessFile("/proc/meminfo", "r");
        load = reader.readLine();

        // Get the Number value from the string
        Pattern p = Pattern.compile("(\\d+)");
        Matcher m = p.matcher(load);
        String value = "";
        while (m.find()) {
            value = m.group(1);
            // System.out.println("Ram : " + value);
        }
        reader.close();

        totRam = Double.parseDouble(value);
        // totRam = totRam / 1024;

        float mb = (float) (totRam / 1024.0f);
        float gb = (float) (totRam / 1048576.0f);
        float tb = (float) (totRam / 1073741824.0f);

        lastValue = gb;
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        // Streams.close(reader);
    }

    return lastValue;
}

From source file:Main.java

public static String oldEncodeQrCodeString(String text) {
    Pattern pattern = Pattern.compile("[A-Z]");
    Matcher matcher = pattern.matcher(text);
    StringBuffer sb = new StringBuffer();
    while (matcher.find()) {
        String letter = matcher.group(0);
        matcher.appendReplacement(sb, QR_CODE_LETTER + letter);
    }//w ww  .  j  a  v  a 2 s .co m
    matcher.appendTail(sb);

    return sb.toString().toUpperCase(Locale.US);
}