Log in

No account? Create an account

t3knomanser's Fustian Deposits

Regexing and Java

How Random Babbling Becomes Corporate Policy

run the fuck away

Mad science gone horribly, horribly wrong(or right).

Regexing and Java

Previous Entry Share Next Entry
run the fuck away
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."

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