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() 

Source Link

Document

Returns the input subsequence matched by the previous match.

Usage

From source file:Main.java

private static String lowerCaseAttributes(String formatted) {
    Matcher m = ID_PATTERN.matcher(formatted);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        String text = m.group();
        m.appendReplacement(sb, Matcher.quoteReplacement(text.toLowerCase()));
    }/*from  www  .  j  a v a  2  s  .co m*/
    m.appendTail(sb);
    return sb.toString();
}

From source file:Main.java

public static String getVlaueFromAnnotation(Annotation annotation, String annName) {
    if (cache == null) {
        cache = new LruCache(500);
    }/*  www. ja  v a  2s . c o  m*/
    String annotationString = annotation.toString();
    String cacheKey = "getVlaueByColumnAnnotation:" + annotationString.hashCode() + "," + annName;
    String ret = (String) cache.get(cacheKey);
    if (ret == null || "".equals(ret)) {
        String pattern = annName + "=(.*?),";
        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(annotation.toString());
        if (m.find()) {
            ret = m.group();
            ret = ret.substring(annName.length() + 1, ret.length() - 1);
        }
        cache.put(cacheKey, ret);
    }
    return ret;
}

From source file:Main.java

public static String IntegerToString(String str) {
    Pattern p = Pattern.compile("&#[0-9]{5};");
    Matcher m = p.matcher(str);
    String g = "";
    String num = "";
    char c = 0;/*from  www .ja  v a 2s.co m*/
    while (m.find()) {
        g = m.group();
        num = g.substring(2, 7);
        c = (char) (Integer.parseInt(num));
        str = str.replace(g, "" + c);
    }
    return str;
}

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 a 2 s .  c om*/
        }
        return content;
    } else {
        return "";
    }
}

From source file:Main.java

public static int extractInt(String str) {
    Matcher matcher = Pattern.compile("\\d+").matcher(str);

    if (!matcher.find())
        throw new NumberFormatException("For input string [" + str + "]");

    return Integer.parseInt(matcher.group());
}

From source file:Main.java

public static String numberCheck(String num) {
    if (num == null || num.length() == 0) {
        return "";
    }//  w ww  .  j  ava  2 s.c om
    Pattern pattern = Pattern.compile("(?<!\\d)(?:(?:1[34578]\\d{9})|(?:861[34578]\\d{9}))(?!\\d)");
    Matcher matcher = pattern.matcher(num);
    StringBuffer bf = new StringBuffer(64);
    while (matcher.find()) {
        bf.append(matcher.group()).append(",");
    }
    int len = bf.length();
    if (len > 0) {
        bf.deleteCharAt(len - 1);
    }
    return bf.toString();
}

From source file:Main.java

public static void findPattern(String regex, String source) {
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(source);

    System.out.println("Regex:" + regex);
    System.out.println("Text:" + source);
    while (m.find()) {
        System.out.println("Matched  Text:" + m.group() + ", Start:" + m.start() + ", " + "End:" + m.end());
    }/* w  w  w. ja  v  a 2 s .  c o  m*/
}

From source file:Main.java

public static List<String> findFileInCardText(String cardText, String[] fileExtensions) {

    List<String> filesFound = new ArrayList<String>();
    if (fileExtensions == null || fileExtensions.length == 0) {
        assert false : "fileExtensions should never be empty or null";
        return filesFound;
    }/*from  w  w w  . ja v  a 2  s  .  com*/

    StringBuilder extensionPatternBuilder = new StringBuilder();

    // File name pattern
    extensionPatternBuilder.append("[A-Za-z0-9_-]+");

    // extension pattern
    extensionPatternBuilder.append("\\.(");
    for (int i = 0; i < fileExtensions.length; i++) {
        // The format is ext1|ext2|ext3 so the first occurance
        // does not have a |.
        if (i == 0) {
            extensionPatternBuilder.append(fileExtensions[i]);
        } else {
            extensionPatternBuilder.append("|" + fileExtensions[i]);
        }
    }
    extensionPatternBuilder.append(")");

    // The regex here should match the file types in SUPPORTED_AUDIO_FILE_TYPE
    Pattern p = Pattern.compile(extensionPatternBuilder.toString());
    Matcher m = p.matcher(cardText);
    while (m.find()) {
        filesFound.add(m.group());
    }
    return filesFound;
}

From source file:Main.java

/**
 * Converts the given xpath express to uppercase tags. All tags in IE are
 * returned as upper case and if the xpath isn't converted, no tags will match
 * the xpath.//w  w  w. j a  v a 2  s .c  om
 */
protected static String convertXPath(String xpath) {
    Matcher matcher = p.matcher(xpath);
    StringBuffer buffer = new StringBuffer();
    while (matcher.find()) {
        String group = matcher.group();
        if (group.matches("\\/[\\w]*")) {
            buffer.append(group.toUpperCase());
        } else {
            buffer.append(group);
        }
    }
    return buffer.toString();
}

From source file:Correct.java

public static void execute(String One, String Two) {

    Two = Two.replaceAll("\\\\n", "\n");
    try {//  w  ww.  j av  a2 s  . c o m
        System.out.println("Regex = " + One);
        System.out.println("Input = " + Two);

        Pattern pattern = Pattern.compile(One);
        Matcher match = pattern.matcher(Two);

        while (match.find()) {
            System.out.println("Found [" + match.group() + "]\nStarting at " + match.start() + " , \nEnding at "
                    + (match.end() - 1));
        }
    } catch (PatternSyntaxException pse) {

        System.err.println("Bad regex: " + pse.getMessage());
        System.err.println("Description: " + pse.getDescription());
        System.err.println("Index: " + pse.getIndex());
        System.err.println("Incorrect pattern: " + pse.getPattern());
    }
}