Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

using regex question  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

\d{5}(-\d{4})?

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 ]
 
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use Matcher.matches
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Example code

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!