Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular Expression problem

 
tihor Gupta
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12087
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
Stefaan Dutry
Ranch Hand
Posts: 32
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic