Word wildcard search
Posted on 2005-04-24
I want to create a word search engine using the wildcard (*). I've made some research on the net and here for more information and found something about regex.
his seems to be the best way to do it but I'm not sure I understand correctly, so I'd like if someone could help me with my function.
Here it is:
public void search (String searchedWord)
// We go throught the vector of words and compare every words.
// The vector "words" is already defined and filled.
for (int i = 0; i < words.size(); i++)
String currWord= (String) words.elementAt(i);
// This represent the current word of the vector ?
Pattern p = Pattern.compile(currWord);
// This is the searched word with the wildcard (which is always *) ? I'm not sure how to use this...
Matcher m = p.matcher(searchedWord);
// We compare both words and print if it matches
if (m.matches()) System.out.println(currWord);
This is how it should works. The user enters a word with any numbers of wildcard, which will always be represented by a *. We then start the research and print every word that match. Thanks,