正则表达式恰好是n OR m次 [英] Regex exactly n OR m times

查看:145
本文介绍了正则表达式恰好是n OR m次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下正则表达式,其中 X 任何正则表达式。

Consider the following regular expression, where X is any regex.

X{n}|X{m}

这个正则表达式会测试 X 发生完全 n m 次。

This regex would test for X occurring exactly n or m times.

是否有可以测试事件的正则表达量词 X 完全 n m 次?

Is there a regex quantifier that can test for an occurrence X exactly n or m times?

推荐答案

没有单个量词意味着恰好m或n次。你这样做的方式很好。

There is no single quantifier that means "exactly m or n times". The way you are doing it is fine.

另一种选择是:

X{m}(X{k})?

其中 m< n k n-m 的值。

这篇关于正则表达式恰好是n OR m次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆