Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular Expression problem

 
tihor Gupta
Greenhorn
Posts: 1
  • 0
  • 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
Pie
Posts: 12021
25
Chrome Java Linux
  • 0
  • 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
Pie
Posts: 47274
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
Stefaan Dutry
Ranch Hand
Posts: 32
Eclipse IDE Java
  • 0
  • 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.
     
    I agree. Here's the link: http://aspose.com/file-tools
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic