PHP PCRE 匹配大于、小于字符串值

PHP PCRE match bigger than, lower than string values

考虑使用 PCRE 验证可能包含的输入值:

200
<200
>200
<=200
>=200

匹配 <=>= 字符序列的最佳方法是什么?到目前为止我有这个:

[<|>|<=|>=]{0,2}\d+

您弄错了character class with the grouping operator。考虑:

(?:<|>|<=|>=)?\d+

或者,如果您想保存分组以供以后逻辑:

(<|>|<=|>=)?(\d+)