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
:)
Robert Mark Bram - 16 Mar 2006 06:57 GMT
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.... :)
Robert Mark Bram - 16 Mar 2006 07:05 GMT
*sigh*
Actually, that 'solution' doesn't work for 1, 11 etc. mm.. :(
Oliver Wong - 16 Mar 2006 19:47 GMT
> Hi All,
>
[quoted text clipped - 19 lines]
> 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
Alan Krueger - 17 Mar 2006 05:14 GMT
> 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.
[...]
> I am testing with this demo applet:
> http://jakarta.apache.org/oro/demo.html
Curiously, it appears to work with java.util.Pattern.
http://www.cis.upenn.edu/~matuszek/General/RegexTester/regex-tester.html