Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

oro regular expression

Thread view: 
Robert Mark Bram - 16 Mar 2006 06:50 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.