简体   繁体   English

如何找到所有大于 110011 的二进制数的正则表达式

[英]How do I find the regular expression for- All binary numbers greater than 110011

I am trying to solve a problem set to practice for an exam.我正在尝试解决为考试练习设置的问题。 How can I approach questions like these?我该如何处理这些问题? Is there a way to verify solutions or is it just trial and error?有没有办法验证解决方案,还是只是反复试验?

This one seems quite simple: the string has to be one of:这看起来很简单:字符串必须是以下之一:

  • 1 followed by at least six more characters. 1 后跟至少六个字符。
  • 111 followed by at least (or exactly) three characters 111 后跟至少(或恰好)三个字符
  • 1111 followed by at least (or exactly) two characters. 1111 后跟至少(或恰好)两个字符。

If the input can start with leading 0s, change all the leading "1"s to "0*1".如果输入可以以前导 0 开头,则将所有前导“1”更改为“0*1”。 In any case, it can be factored out.无论如何,它都可以分解出来。

The answer to your question, "is there a simple algorithm which can do that for me?"您问题的答案是“是否有一个简单的算法可以为我做到这一点?” is probably "no".可能是“不”。 But the above is more simple logic than trial-and-error.但以上是比试错更简单的逻辑。 Writing down random regular expressions until you find one which works is not a good way to solve the problem, given the difficulty of algorithmically proving correctness.考虑到通过算法证明正确性的难度,写下随机的正则表达式直到找到一个有效的正则表达式并不是解决问题的好方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM