开发者

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)


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜