aspose file tools*
The moose likes Java in General and the fly likes Cannot get regular expression pattern match to work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Cannot get regular expression pattern match to work" Watch "Cannot get regular expression pattern match to work" New topic
Author

Cannot get regular expression pattern match to work

Tanya Ruttenberg
Ranch Hand

Joined: Jun 22, 2009
Posts: 40
Here is the code:


b comes out to false except when s and x are identical.

I thought I knew something about regular expressions, but clearly I am missing something basic.

Where am I going wrong? Thanks in advance. This is such a helpful website.

TDR
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Tanya Ruttenberg wrote:Here is the code:


b comes out to false except when s and x are identical.


Correct. As explained in the docs.
http://docs.oracle.com/javase/6/docs/api/java/util/regex/Matcher.html#matches() says: "Attempts to match the entire region against the pattern."

So you can either do matches(".*where.*+") or you can look into other methods, such as find(), if I'm not mistaken.

Or, if your matching requirements are really just String literals, you can skip regex altogether and just use String.contains().
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot get regular expression pattern match to work