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

public static String matchUrl(String text) {
    if (TextUtils.isEmpty(text)) {
        return null;
    }/*www  .ja va2  s. c  om*/
    Pattern p = Pattern.compile("[http]+[://]+[0-9A-Za-z:/[-]_#[?][=][.][&]]*", Pattern.CASE_INSENSITIVE);
    Matcher matcher = p.matcher(text);
    if (matcher.find()) {
        return matcher.group();
    } else {
        return null;
    }
}

From source file:Main.java

public static String getEventOfExpression(String expression) {
    // pattern for events
    Pattern eventPattern = Pattern.compile("^[\\w\\W&&[^/\\[\\]]]+(\\[[\\w\\W&&[^\\[\\]]]+\\])?(/[\\w\\W]+)?$");
    Matcher eventMatcher = eventPattern.matcher(expression);
    if (eventMatcher.find() && (eventMatcher.group().length() == expression.length())) {
        StringTokenizer st = new StringTokenizer(expression, "[]/");
        return st.nextToken();
    }/*ww w.j a va2s  .c  o  m*/
    return null;
}

From source file:Main.java

public static String patternLoginVerificationCode(String patternContent) {
    if (TextUtils.isEmpty(patternContent)) {
        return null;
    }/*from   w w  w  . j a v  a 2  s .com*/
    Pattern p = Pattern.compile("(?<!\\d)\\d{6}(?!\\d)");
    Matcher matcher = p.matcher(patternContent);
    if (matcher.find()) {
        return matcher.group();
    }
    return null;
}

From source file:Main.java

/**
 * form file extention to lower case/*  www . j ava 2s  .c o m*/
 * 
 * @param fileName
 * @return
 */
public static String lowerExtension(String fileName) {

    Pattern p = Pattern.compile(pattern);
    Matcher m = p.matcher(fileName);
    if (m.find()) {
        String extName = m.group().toLowerCase();
        fileName = fileName.replaceAll("(.[a-zA-Z0-9]+)$", extName);
    }

    return fileName;
}

From source file:Main.java

public static String patternCode(String patternContent) {
    if (TextUtils.isEmpty(patternContent)) {
        return null;
    }/* w  w w  .  j  ava  2  s.c  o m*/
    Pattern p = Pattern.compile("(?<!\\d)\\d{4}(?!\\d)");
    Matcher matcher = p.matcher(patternContent);
    if (matcher.find()) {
        return matcher.group();
    }
    return null;
}

From source file:Main.java

/**
 * Search the first matched string//from w  ww  . j  av  a 2 s  .c o m
 * @param str
 * @param regex
 * @return
 */
public static String getMatchedString(String str, String regex) {
    String ret = null;

    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(str);
    if (matcher.find()) {
        ret = matcher.group();
    }

    return ret;
}

From source file:Main.java

public static String getActionOfExpression(String expression) {
    // pattern for actions
    Pattern actionPattern = Pattern
            .compile("^([\\w\\W&&[^/\\[\\]]]+)?(\\[[\\w\\W&&[^\\[\\]]]+\\])?(/[\\w\\W]+)$");
    Matcher actionMatcher = actionPattern.matcher(expression);
    if (actionMatcher.find() && (actionMatcher.group().length() == expression.length())) {
        String action = expression.substring(expression.lastIndexOf("/") + 1);
        return action;
    }//  w w  w . j  a v a2  s  .  co  m
    return null;
}

From source file:Main.java

public static String patternCode(String patternContent) {
    if (TextUtils.isEmpty(patternContent)) {
        return null;
    }//from ww  w. j av a2 s  .c o  m
    Pattern p = Pattern.compile("(?<!\\d)\\d{6}(?!\\d)");
    Matcher matcher = p.matcher(patternContent);
    if (matcher.find()) {
        return matcher.group();
    }
    return null;
}

From source file:Main.java

public static String getYoutubeIdFormUrl(String url) {
    String pattern = "(?<=watch\\?v=|/videos/|embed\\/)[^#\\&\\?]*";

    Pattern compiledPattern = Pattern.compile(pattern);
    Matcher matcher = compiledPattern.matcher(url);

    if (matcher.find()) {
        return matcher.group();
    }//  www.  j  a v  a 2s. co m
    return "";
}

From source file:Main.java

public static List<String> getMatches(String regex, CharSequence input) {
    if (input == null)
        return null;
    List<String> matches = new ArrayList<>();
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(input);
    while (matcher.find()) {
        matches.add(matcher.group());
    }//w w  w.  jav a2s .co  m
    return matches;
}