Regular expressions: Matching if number is greater then…?

前端 未结 4 1470
灰色年华
灰色年华 2021-01-16 03:03

I am in the need of an regexp that checks if one numerical value is greater then another value. Pretty much like I would by writing (if 10>8) ...

Cl

4条回答
  •  日久生厌
    2021-01-16 03:40

    If I understand your problem correctly, you want a regex which matches two consecutive numbers of arbitrarily length where the second is greater than the first. This is not possible to do with regexen. It's clearly not a regular language and none of the common extensions (backreferences, recursive references) are powerful enough to change that.

    In some regex implementations (e.g. perl's) it's possible to embed code in the host language into the regex. In that case you can of course just embed the predicate num1 < num2 as perl code, but I don't think that counts as a solution as a regex.

提交回复
热议问题