This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Regular Expression problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regular Expression problem" Watch "Regular Expression problem" New topic
Author

Regular Expression problem

tihor Gupta
Greenhorn

Joined: Jan 12, 2011
Posts: 1
I want to create pattern for checking a string such that it contains numbers 0-9. Its length should be 2-3. But it should not contain 00 or 000.

How can i create a regular expression for this.

Rohit
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11150
    
  16

What have you tried? We generally don't just hand out answers, but expect you to show some kind of effort first. Post the regex you've written so far, and we can work from that.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37900
    
  22
And welcome to JavaRanch
Stefaan Dutry
Ranch Hand

Joined: Sep 17, 2010
Posts: 32

Although at first it sounds realy easy you need quite a few regex constructs.

A possible solution i have in mind(and tested) involves using the following regex elements:
  • quantifiers
  • boundary matchers
  • negative lookahead


  • Some usefull links are:
  • Pattern javadoc
  • online regex tester
  • java regex tutorial


  • Post what you have so far and i'll see how i can help.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Regular Expression problem
     
    Similar Threads
    Can XSL sheets see Session Vars?
    Input parameter check function ??
    TextArea processing
    regular expression to Remove field inside [ ] brackets
    make text bold