views:

128

answers:

1

I'd like to know how to create a regex to validate a function like this:

=TRIMESTER(1,2,2008)

The first parameter should be any integer. The second parameter is an integer that shouldn't be higher than 4. The third parameter is a year (4 digits)

+2  A: 

Is this what you want?

=TRIMESTER\(\d+,[1-4],\d{4}\)

It matches any number of digits (at least one) for the first parameter, any digit between 1 and 4 (included) for the second and any four digits for the last one.

Or, if you want to validate only the second parameter, this:

[1-4]

but I would prefer simple comparison for that, like this:

AND(x >= 1; x <= 4)
Martinho Fernandes
I'm testing it but if I put a 2 or more digit on the first parameter I get false as the validation result.
Raúl Roa
In the original post I missed a `+`. I fixed it in the meanwhile. Perhaps you didn't notice that?
Martinho Fernandes
Excellent, thanks.
Raúl Roa