package com.mindprod.example;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Test Matching with a Regex.
* <p/>
* Use a regex to check that an entire string precisesly matches a regex pattern,
* with no characters left over in the pattern or the String.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.1 2008-01-29
* @since 2009
*/
public class TestRegexMatch
{
private static final Pattern pattern = Pattern.compile( "\\<td>([^\\<>]++)\\</td>" );
/**
* test harness
*
* @param args not used
*/
public static void main( String[] args )
{
final String lookIn = "<td>orca</td>";
final Matcher m = pattern.matcher( lookIn );
if ( m.matches() )
{
final int gc = m.groupCount();
for ( int i = 0; i <= gc; i++ )
{
System.out.println( i + " : " + m.group( i ) );
}
}
}
}