[英]Validate LHS+OPERATOR+RHS regular expression in JavaScript?
我只有這些運算符: >
、 >=
、 <
、 <=
、 ==
、 !=
、 matches
我有一些像下面這樣的值和預期的結果
<1.1> == 10 Match
<1.1> != 10 Match
<1.1> matches test Match
<1.1> matches test|user Match
<1.1> matches 10 Match
<1.1> matches 10|20 Match
<1.1> >= 10|20 Don't Match
<1.1> == 10|20 Don't Match
<1.1> != test Don't Match
<1.1> == test Don't Match
我試過這個
/^[a-zA-Z0-9_.<>]+[\s](<|<=|>|>=|==|!=|matches)[\s][a-zA-Z0-9_.<>|]+$/
但不工作。
您可以使用以下內容:
/^[a-zA-Z0-9_.<>]+\s(?:(?:<|<=|>|>=|==|!=)\s\d+|matches\s[a-zA-Z0-9_.<>|]+)$/gm
我添加了一個選項來將匹配項與其他操作符分開。 你可以在這里看到一個演示
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.