Hello,

I have a few strings with the patterns : "1234AB", "1234ABC", "AB1234CDE" which I am trying to match. For starters, i don't know if I have the regular expressions correct. When I compile, I get some of the desired results but I also get some duplicates. Can someone please help me figure out the proper regular expression?.

Also, I was trying to match more than one pattern and I am not doing too well with that either.

I would really appreciate some help....Please.

Thanks.

Java Code:
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexMatches
{
	
 public static void main( String args[] )
	{
	 // create regular expression
	 Pattern ex1 = Pattern.compile( "[A-Z][A-Z]\\d{4,5}[A-Z][A-Z]+" );
	 Pattern ex2 = Pattern.compile( "\\d{4,5}[A-Z][A-Z][A-Z]+" );
	 Pattern ex3 = Pattern.compile( "\\d{4,5}[A-Z][A-Z][A-Z]\\d+" );
	 
	 String string1 = "1234ABC\n" +
	"1234AB\n" +
	"1234AB1\n" +
	"1234a\n" +
	 "AB1234CDE\n";
	
	 // match regular expression to string and print matches
	 Matcher matcher = (ex1.matcher( string1 ));
	 Matcher matcher2 = (ex2.matcher( string1));
	 while ( (matcher.find())||(matcher2.find()))
			System.out.println( matcher.group() );
	 		System.out.println( matcher2.group() );
	 
	} // end main
} // end class RegexMatches