File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Pattern.matches woes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pattern.matches woes" Watch "Pattern.matches woes" New topic

Pattern.matches woes

ilteris kaplan
Ranch Hand

Joined: Jan 21, 2006
Posts: 38
Hello, I am using regex to check some links on my code and basically I I want to know whether they have certain words in those urls.

The way I am checking this is below:

apparently matches tries to match for the whole newurl to google. I tested it by changing the newurl = "google" and it returned me true. so can someone address me what I am doing wrong here?

thanks a lot.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Instead of using Pattern.match() which does match the entire string, why not just use another Matcher and its find() method to see if part of the string matches the term?

The other option is to use a regex pattern that will catch any prefix or suffix to the desired pattern. So .*google.* as an example.
ilteris kaplan
Ranch Hand

Joined: Jan 21, 2006
Posts: 38
working like a charm.
I agree. Here's the link:
subject: Pattern.matches woes
It's not a secret anymore!