Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pattern.matches woes

 
ilteris kaplan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks!!
working like a charm.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic