File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Regular Expression problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 9948
    
    6

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.


Never ascribe to malice that which can be adequately explained by stupidity.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32675
    
    4
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
    Input parameter check function ??
    make text bold
    regular expression to Remove field inside [ ] brackets
    Can XSL sheets see Session Vars?
    TextArea processing