How Random Babbling Becomes Corporate Policy (t3knomanser) wrote,
How Random Babbling Becomes Corporate Policy

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."

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

  • Strange Things People Say About Me (to my face)

    Recently, I've been at the center of a trend. That trend is complete strangers asking me "Are you ____?" A quick summary. For example: Are you…

  • Writer's Block: If I could find my way

    -10,000 years, at minimum. Tomorrow is always better than today, especially when you can't fact-check.

  • Bob Morlang

    When I was working at Tri-Mount, we had these camp trucks. They were army surplus, and while they could take a beating, they only sort of worked. And…

  • Post a new comment


    Comments allowed for friends only

    Anonymous comments are disabled in this journal

    default userpic

    Your IP address will be recorded