首页 > 解决方案 > 使用正则表达式在字符串中查找 0-360

问题描述

我想写一个正则表达式,它可以提取字符串中 0 到 360 之间的数字。以下是示例:

Text: "Rotate by 360 degrees"
OP: 360

Text: "36 degrees degree rotation"
OP: 36

Text: "rotate 100"
OP: 100

Text: "rotate 6700"
OP: NA (as 6700 is out of range)

我想通过正则表达式来实现

标签: regex

解决方案


列举可能性:

\b([0-2]?[0-9]{1,2}|3[0-5][0-9]|360)\b

推荐阅读