我需要一个正则表达式,匹配并在满足条件时从字符串返回2个数字
仅限最大为2位数且不大于29的数字(可能包括十进制大小写-因此最多2位数加上1个十进制大小写)
它们必须在y
或+
中的一个字符之间,在第二个数字之后是单词“houses”
然后捕捉两个数字
对于以下字符串:
8 y 13 houses, 13 y 8 houses, 13 y 13 houses, 8 y 8 houses, 120 y 8 houses, 8 y 120 houses, 13,5 y 8 houses, 13,5 y 120 houses
我会得到
^{pr2}$我试着用这个
^{3}$但也没办法得到','。在
试试看:
演示:
^{pr2}$当正则表达式与输入中的字符串匹配时,第一个数字将位于
match.group(1)
中,第二个数字将位于match.group(3)
中。在如果要将可选十进制值与可选组匹配,请执行以下操作:
其中},然后是{}。在
(?:,[0-9])?
将匹配逗号后跟数字(如果存在)。注意,我将数字匹配限制为0到29之间的值;首先匹配可选的1
或{演示:
^{pr2}$相关问题 更多 >
编程相关推荐