Image

Regexing and Java

For some reason, I can regex in PERL, but not in Java.

I'm putting together a web service that works as a web based content filtering system. Long story short, one section of this involves a basic keyword matching, where it pulls a list of naughty words out of a database, and attempts to match them in the text of the page.

I tried using the matches() function of the string datatype, and when I couldn't get that to work, I instead used the Pattern/Matcher out of java.util.regex.

Right now, my code looks something like this:
Pattern p = Pattern.compile(".*?" + word + ".*?");
Matcher m = p.matcher(page);
if (m.matches()) {
//do stuff

}


In theory, the pattern should be, "any character, any number of times (but don't be greedy) followed by word followed by any character any number of times." Unfortunately, it never returns a match- even when the value in word is clearly in the page.

Am I going about this stupid? This seems so simple, yet is obviously not.