Re: Regular Expression question
From: Glenn Jackman (xx087_at_freenet.carleton.ca)
Date: 04/12/04
- Next message: John H. Harris: "TIP #185: Null Handling"
- Previous message: Bryan Oakley: "Re: Regular Expression question"
- In reply to: Justin Miller: "Regular Expression question"
- Next in thread: Justin Miller: "Re: Regular Expression question"
- Reply: Justin Miller: "Re: Regular Expression question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 12 Apr 2004 18:22:16 GMT
Justin Miller <grayghostx@yahoo.com> wrote:
> <range> ::= <digit|real>-<digit|real>
> <digit> ::= 0-9
> <real> ::= <digit>.<digit>
>
> As an example, the input could be a range like: 4-12
> Or it could be in the form of floats: .5-1.7
>
> The form where you have normal integers is trivial, but I also want it
> to be able to validate that, in the case of the real number example,
> that the user didn't simply enter a period by itself. You can have 1.,
> .1, 1.5, etc. Just not a single period.
My regex would be: (\d+(?:\.\d*)?|\.\d+)-(\d+(?:\.\d*)?|\.\d+)
# a number is:
# some digits followed optionally by a dot and maybe more digits
# or a dot followed by some digits
set number {\d+(?:\.\d*)?|\.\d+}
# a range is a number followed by a hyphen followed by a number
set range "($number)-($number)"
regexp $range ".5-1.7" -> low high
-- Glenn Jackman NCF Sysadmin glennj@ncf.ca
- Next message: John H. Harris: "TIP #185: Null Handling"
- Previous message: Bryan Oakley: "Re: Regular Expression question"
- In reply to: Justin Miller: "Regular Expression question"
- Next in thread: Justin Miller: "Re: Regular Expression question"
- Reply: Justin Miller: "Re: Regular Expression question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|