package com.mindprod.example;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* use a regex to find all instances of a Pattern in a string.
* <p/>
* composed with IntelliJ IDEA
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0, 2008-01-29
*/
public class TestFindWithRegex
{
private static final Pattern p = Pattern.compile( "\\<td>([^\\<>]++)\\</td>" );
/**
* test harness
*
* @param args not used
*/
public static void main( String[] args )
{
final String lookIn = "dolphin <td>orca</td> junk\n"
+ "<td></td> empty"
+ "<td>pilot whale</td> beluga\n";
final Matcher m = p.matcher( lookIn );
while ( m.find() )
{
final int gc = m.groupCount();
for ( int i = 0; i <= gc; i++ )
{
System.out.println( i + " : " + m.group( i ) );
}
}
}
}