Return to Snippet

Revision: 16201
at July 28, 2009 19:06 by aadsm


Updated Code
import java.util.regex.Matcher;
import java.util.regex.Pattern;

// Java -has- issues
public String[] getMatches( String string, String regexp )
{
    String[] matches    = new String[0];
    Pattern pattern     = Pattern.compile(regexp);
    Matcher matcher     = pattern.matcher(string);
    boolean matchFound  = matcher.find();

    if( matchFound )
    {
        matches = new String[matcher.groupCount()];
        for( int i = 0; i <= matcher.groupCount(); i++ )
        {
            matches[i] = matcher.group(i);
        }
    }
    
    return matches;
}

Revision: 16200
at July 28, 2009 19:02 by aadsm


Initial Code
// Java -has- issues
public String[] getMatches( String string, String regexp )
{
    String[] matches = new String[0];
    Pattern pattern = Pattern.compile(regexp);
    Matcher matcher = pattern.matcher(string);
    boolean matchFound = matcher.find();

    if( matchFound )
    {
        matches = new String[matcher.groupCount()];
        for( int i = 0; i <= matcher.groupCount(); i++ )
        {
            matches[i] = matcher.group(i);
        }
    }
    
    return matches;
}

Initial URL

                                

Initial Description

                                

Initial Title
Missing getMatches function

Initial Tags
regexp

Initial Language
Java