• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help in using Regular Expression  RSS feed

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Text box can contain only maximum of four digits and it can be integers thus if enter a single value it should not be 0(zero) + it can also accepts string value "many","MANY","few" and "FEW" in it.

I tried using "(\d(1)?[1-9]{1,4})|(FEW)|(few)|(MANY)|(many)" to avoid entering 0 as first value but it fails if we enter "00","000""0000" + I could not restrict the size to be 4 digit max.

Can anybody help me to write regular expression for the above conditions or any sample example code for the above case.
 
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure about the escape-symbols, but a valid number has to start with 1-9, right?
([1-9]....
and is followed by maximum 3 additional numbers:
[0-9]{0,3})...
or is one of the tokens:
|(FEW)|(few)|(MANY)|(many)
so we get:
([1-9][0-9]{0,3})|(FEW)|(few)|(MANY)|(many)
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Ramadoss"-
Welcome to the JavaRanch! We like to keep a nice professional lookin' image... (we don't want anyone to show up the Moose). So, can you please adjust your displayed name to match the JavaRanch Naming Policy? Basically it should be a believeable and not obviously fictitious first and last name.
You can change it here.

Thanks! and again welcome to the JavaRanch!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!