oro regular expression

R

Robert Mark Bram

Hi All,

I want an expression that will allow a decimal number or a specific
string. For example, I want the following to be valid:

..1
1
1.1
-.1
-1
-1.1
remove
REMOVE
REmove

Here is the regular expression I am testing:
-{0,1}\d{0,5}(\.(\d){0,2})?|(?i)REMOVE
It accepts the numbers, but not the strings.

If I use this:
-{0,1}\d{1,5}(\.(\d){0,2})?|(?i)REMOVE
it accepts the string and most numbers, but not this:
..1

I am testing with this demo applet:
http://jakarta.apache.org/oro/demo.html

Can anyone figure what I am doing wrong? Any help would be most
appreciated!

Rob
:)
 
R

Robert Mark Bram

I have a solution, but I don't understand why it works:
(?i)REMOVE|(-?\d{0,5}(\.)?\d{0,2})

This now accepts all the combinations I wanted, but I don't understand
why.... :)
 
O

Oliver Wong

Robert Mark Bram said:
Hi All,

I want an expression that will allow a decimal number or a specific
string. For example, I want the following to be valid:

.1
1
1.1
-.1
-1
-1.1
remove
REMOVE
REmove

Here is the regular expression I am testing:
-{0,1}\d{0,5}(\.(\d){0,2})?|(?i)REMOVE
It accepts the numbers, but not the strings.

If I use this:
-{0,1}\d{1,5}(\.(\d){0,2})?|(?i)REMOVE
it accepts the string and most numbers, but not this:
.1

Draw a DFA and convert it to an RE. Read Michael Sipser's book
"Introduction to the Theory of Computation" if you don't know how. I'd do it
for you, but it's a lot of effort, and you wouldn't understand how I got to
my result unless you knew Sipser's method. =/

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top