Matcher

Hi,

i have a larg number of item seperated by semicolons and stroed in a String object.

each item could includ pattern...we have following patterns:

1- * (Asterisks)Use asterisk to filter on a match of zero or more characters.

2- ! (Exclamation Mark)Use exclamation mark to filter the search using the NOT operator.

3- && (Ampersand)Use ampersand to filter objects where a single value should be matched with many patterns.

4- \ (Back Slash)Use back slash to filter objects when the name of the object itself contains a comma. This character is called an escape sequence because it avoids searching for objects, as if they had two different names.

5- <between> value1 and value2

an example of such String object is : a*,!b, a* && !c,.....

suppose i have a method named isValid(String item), the caller of this method pass a single item like "amesterdam" to this method and this method returns true just if the item matched in the String object.

the question is: what is the best way to matching one item from this String?

Rgrds

now i have

[1140 byte] By [Sarah_Mahdavia] at [2007-10-3 0:45:14]
# 1
Just throw all that stuff out and use something that might be considered standard for this sort of stuff. Regex might be a good idea? Hmm?
RadcliffePikea at 2007-7-14 17:39:53 > top of Java-index,Other Topics,Algorithms...
# 2

As an alternative to Mr. Pike's suggestion, which I actually endorse but which I also recognize might not be possible, might I suggest that at the same time that you are looking at regular expressions, you might consider if it is possible to translate your pattern string into a regular expression.

your commas are alternation (logical or, this pattern fits OR the next pattern fits) your ampersands are logical ands, your star is a closure and you will see that your match string is really not very different from a regexp to begin with. It should not be too difficult to take one of your pattern strings, map it character by character to a regular expression string and then use that do do your matching.

marlin314a at 2007-7-14 17:39:53 > top of Java-index,Other Topics,Algorithms...