包含至少两个 0 和至少一个 1 的所有二进制字符串的正则表达式?
我想它会是(E0 * 0 * EUE1 * E)? 其中 E 是我的字母表的集合,至少有 2 个 0 和至少 1 个 1
Im thinking it would be (E0*0*EUE1*E)?
where E is the set of my alphabet, with at least 2 0s and at least 1 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试这个表达式:
编辑
可以简化为:
Try this expression:
EDIT
Could be simplified to:
如果您被允许使用前瞻,我将这样做:(在带有注释的 PHP 自由间距模式下。)
请注意,您可以在字符串的开头放置任意数量的前瞻(其在逻辑 < 中工作) code>AND 方式),指定多个逻辑要求。
If you are allowed to use lookahead, here is how I'd do it: (in PHP free-spacing mode with comments.)
Note that you may place any number of lookaheads at the beginning of the string (which work in a logical
AND
manner), to specify multiple logical requirements.建议的解决方案是错误的,因为它还会接受
000000000
其中 E={0,1}。请注意,1* 表示任意数量的 1 [包括无]E* * (0E*0E*1+0E*1E*0+1E*0E*0) * E*
都可以:所有可能0,0,1 的排列,并尽可能插入 E* [这样您就可以在所需元素之间/之前插入任意数量的字符]。在正则表达式语法中,它是:.*(0.*0.*1|0.*1.*0|1.*0.*0).*
The suggested solution is wrong, since it will also accept
000000000
where E={0,1}. note that 1* means any number of 1's [including none]E* * (0E*0E*1+0E*1E*0+1E*0E*0) * E*
would work: all possible permutations of 0,0,1, and insert E* wherever possible [so you can insert any numbers of characters between/before the required elements]. In regex syntax it is:.*(0.*0.*1|0.*1.*0|1.*0.*0).*
(.*00+.1+.)|(.* 1+ .* 00+.*)
以上是自我解释
。是任意字符
+ 是一个或多个
(.*00+.1+.)|(.* 1+ .* 00+.*)
the above is self explaining
. is any character
+ is one or more