Raúl Roa
Raúl Roa

Reputation: 12386

REGEX to validate excel like mathematical expressions

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)

Upvotes: 0

Views: 432

Answers (1)

R. Martinho Fernandes
R. Martinho Fernandes

Reputation: 234584

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)

Upvotes: 2

Related Questions