wood burning stoves
The moose likes Java in General and the fly likes using regex question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "using regex question" Watch "using regex question" New topic

using regex question

Paro Karisian

Joined: Oct 14, 2004
Posts: 2
I want to use regex to match against patterns I set in an XML schema. The problem is that Matcher.find() returns a match even if it's only a partial match. For example, here is a pattern for zip code:


I only want it to return true if the ENTIRE input string matches the pattern.

So, "55555" or "55555-2222" should return true, but "55555-23" or "523121" returns false. Matcher.find() will always find a match for any of these values. What is the best way to make it return true only in the case that the entire input string matches?
[ October 14, 2004: Message edited by: Paro Karisian ]
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Use Matcher.matches

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Example code

Java Developer, Thailand
I agree. Here's the link: http://aspose.com/file-tools
subject: using regex question
It's not a secret anymore!