Java Matcher getMatchGroup(String source, String rex, int groupIndex)

PreviousNext

get the match group

Parameter:

  • source
  • rex
  • groupIndex

Return:

**

//package com.java2s;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    /**/* w w    w  .  d  em   o   2s   . c   o  m */
     * get the match group
     * 
     * @author Young
     * @param source
     * @param rex
     * @param groupIndex
     * @return
     */
    public static String getMatchGroup(String source, String rex, int groupIndex) {
        Pattern pattern = Pattern.compile(rex);
        Matcher matcher = pattern.matcher(source);
        if (matcher.find()) {
            return matcher.group(groupIndex);
        }
        return null;

    }
}
PreviousNext

Related