package com.mindprod.example;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.lang.System.*;
/**
* Finding with a Regex.
* <p/>
* Use a regex to see repeated instances of a pattern embedded in a large string .
*
* @author Roedy Green, Canadian Mind Products
* @version 1.1 2009-04-29 restore damaged code
* @since 2008-01-29
*/
public class TestRegexFind
{
/**
* Regex pattern we look for embedded in big string. By default case-sensitive.
*/
private static final Pattern pattern = Pattern.compile( "<td>([^<>]++)</td>" );
/**
* test harness
*
* @param args not used
*/
public static void main( String[] args )
{
final String lookIn = "</tr><td>orca</td> <td>dolphin</td></tr> then some unrelated junk";
final Matcher m = pattern.matcher( lookIn );
while ( m.find() )
{
final int gc = m.groupCount();
for ( int i = 0; i <= gc; i++ )
{
out.println( i + " : " + m.group( i ) );
}
}
}
}