• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pattern.compile()  RSS feed

 
Johan Lorentzon
Greenhorn
Posts: 9
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I can't get this to work for me. I want to search some text for "xx", to answer my question: does the text contain xx. I've looked up the regular expressions (at least some of them) but I can't get it to work. I want the boolean to be true if the text contains 2 characters of "x". Please help

 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
m.matches() will only be true if the pattern matches the entire string. Try m.find().
 
Johan Lorentzon
Greenhorn
Posts: 9
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks! That solved it!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!