com.nsftools.zip
Class PatternMatch

java.lang.Object
  extended by com.nsftools.zip.PatternMatch

public class PatternMatch
extends java.lang.Object

This class has a single method that allows you to determine whether or not a given string matches a given pattern. See the information in the isMatch method for more information.

If you're using the JDK (aka the J2SE) 1.4 or higher, you should probably use the java.util.regex package to make Regular Expressions to provide string pattern-matching functionality, because it will give you a much greater range of functionality. There are (at the time of this writing) some good examples of Regular Expression usage here on the Sun website.

For updates or more information about this program, please visit www.nsftools.com

Version:
1.00
Author:
Julian Robichaux

Constructor Summary
PatternMatch()
           
 
Method Summary
 boolean isMatch(java.lang.String checkString, java.lang.String pattern)
          Returns a boolean value indicating whether or not checkString matches the pattern.
static void main(java.lang.String[] args)
          The main method has been provided to allow you to test the class, and to give you an example of calling the isMatch method.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PatternMatch

public PatternMatch()
Method Detail

main

public static void main(java.lang.String[] args)
The main method has been provided to allow you to test the class, and to give you an example of calling the isMatch method.


isMatch

public boolean isMatch(java.lang.String checkString,
                       java.lang.String pattern)
Returns a boolean value indicating whether or not checkString matches the pattern. The pattern can include single characters, a range of characters enclosed in brackets, a question mark (which matches exactly one character), or an asterisk (which matches zero or more characters).

If you're matching a character range, it can be either single characters, like [abc], or a range of characters, like [a-c], or a combination, like [a-clmnx-z]. For example, the pattern 'b[aiu]t' would match 'bat', 'bit', and 'but', and the pattern 'a[1-9]' would match a1, a2, a3, a4, a5, a6, a7, a8, and a9.

This should all work much (exactly?) like file matching in DOS. For example, a pattern of '*.txt' should match all strings ending in '.txt', '*.*' should match all strings with a '.' in them, '*.???' should match strings with a three letter extension, and so on.

Also, please note that the pattern check IS case-sensitive. If you don't want it to be, you should convert the checkString and the pattern to lower-case as you're passing them.