File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply 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: 38
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Cannot get regular expression pattern match to work
 
Similar Threads
for(Object name : collection type)
Static method variables
matching regular expressions
Using iterator question
Regular expression