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


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pattern.matches woes" Watch "Pattern.matches woes" New topic
Author

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
thanks!!
working like a charm.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Pattern.matches woes
 
It's not a secret anymore!