List Info

Thread: numeric comparison (inequality)




numeric comparison (inequality)
user name
2006-05-28 12:58:12
I want to check for a number that is greater then 499... the
whole
strring looks like this "(500 seconds)"

I wrote this reg ex in two parts to check and it works, but
there must
be a more elegant way to do it?


\([5-9]\d{2,}.*seconds\)|\([1-4]\d{3,}.*seconds\)

thanks in advance.

Jason


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

numeric comparison (inequality)
user name
2006-05-28 18:03:07
JasonDamianUs wrote:
> I want to check for a number that is greater then
499... the whole
> strring looks like this "(500 seconds)"
>
> I wrote this reg ex in two parts to check and it works,
but there must
> be a more elegant way to do it?
>
>
> \([5-9]\d{2,}.*seconds\)|\([1-4]\d{3,}.*seconds\)

It's better to factor out the opening parenthesis from the
front of the
alternation(for matching efficiency). and the non-greedy
form .*? might
be better than the greedy one .* in your pattern. But I
guess you need
\s* here.  so,
another way of your pattern can be written
as(untested): 

    \((?:[5-9]|[1-9]\d+)\d\d\s*seconds\)

Xicheng


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )