From: Walter Roberson on 17 Apr 2010 16:21 CyberFrog wrote: > regexp(mystring, '\s[-]?+[0-9]+\.[0-9]?\s', 'match') The \s are not needed to match a number -- they match spaces, which would give you a problem at the beginning of a line or end of line. [-]? can be shortened to -? The + after the ? for the - isn't going to do you any good. I would have to look up exactly what it means in this context... something about the "greediness" of the match perhaps. [0-9] can be abbreviated to \d [0-9]? after the decimal place would match a _single_ optional digit. You need to change the ? to * to match 0 or more digits such as for your 1.9999 example. I note that you have coded the digit before the decimal point with the + quantifier. That is fine if it is mandatory to have at least one digit before the decimal place, but will cause problems if you want users to be able to enter (e.g.) -.5 I note that you have coded the \. without any quantifier. That is fine if it is mandatory that there be a decimal point in the number, but will cause problems if you want users to be able to enter plain integers without a trailing decimal point.
From: CyberFrog on 17 Apr 2010 16:46 Walter Roberson <roberson(a)hushmail.com> wrote in message <hqd57t$mk7$1(a)canopus.cc.umanitoba.ca>... > CyberFrog wrote: > > > regexp(mystring, '\s[-]?+[0-9]+\.[0-9]?\s', 'match') > > The \s are not needed to match a number -- they match spaces, which > would give you a problem at the beginning of a line or end of line. > > [-]? can be shortened to -? > > The + after the ? for the - isn't going to do you any good. I would have > to look up exactly what it means in this context... something about the > "greediness" of the match perhaps. > > [0-9] can be abbreviated to \d > > [0-9]? after the decimal place would match a _single_ optional digit. > You need to change the ? to * to match 0 or more digits such as for your > 1.9999 example. > > I note that you have coded the digit before the decimal point with the + > quantifier. That is fine if it is mandatory to have at least one digit > before the decimal place, but will cause problems if you want users to > be able to enter (e.g.) -.5 > > I note that you have coded the \. without any quantifier. That is fine > if it is mandatory that there be a decimal point in the number, but will > cause problems if you want users to be able to enter plain integers > without a trailing decimal point. Some good points there Walter, I would say though and soemthing which I didn't explain at all there will always be a space before and after the elements which is why i put a \s at the beginning and the end. There will always be a decimal point too. All the others are quite valid, I'll have another look. Cheers
First
|
Prev
|
Pages: 1 2 Prev: working with .txt process content Next: question on how to create different backgrounds |