Formal Binary String Regular Expression (each pair of 00 must have 11 before it)

发布时间:2025-08-06 22:52

技巧11:开启QoS(质量-of-service)进行优先级设置 #生活技巧# #数码产品使用技巧# #无线网络优化技巧#

Here is a way to describe a binary string in which every 00 must have at least two 1s before it.

It is a string that
$\quad$ starts with zero or one 0;
$\quad$ followed by zero or more blocks, where each block is
$\quad\quad$ either one or more 1s followed by a 0, such as 10, 110, 1110, etc,
$\quad\quad$ or two or more 1s followed by two 0s, such as 1100, 11100, 111100, etc;
$\quad$ followed by zero or more 1s.

Translated into regular expression, the description above becomes
$\quad$ (0|ε)(11*0|111*00)*1*

You might want to ask, how can we arrive that kind of description?

The observation here is that the number of consecutive 0s in the string is at most 2, a very small number. That indicates that we can break down the string by enumerate different possibilities of consecutive 0s. To paraphrase rici's comment, we could try using enumeration to simulate conditionals.

Of course, there is a mild stroke of luck involved in the approach above on that language. As a last resort, we can always use a heavier machinery such as constructing a DFA for the language (which can be done in one or several ways) and then converting the DFA to a regular expression.

网址:Formal Binary String Regular Expression (each pair of 00 must have 11 before it) https://klqsh.com/news/view/114136

相关内容

Formal Binary String Regular Expression (each pair of 00 must have 11 before it)
RANDOM.ORG
Module 3 Life now and then & Module 4 Rules and suggestions同步练习(含听力音频+答案+听力原文)外研版九年级下册
How to set up Dual Monitors on Windows 11/10
Fit Testing
Bing’s “Related Searches” Option: How Many People Are Using it?
How to Set Up Multiple Monitors Windows 11: A Step
Pizza Cornicione – What It Is and How to Make It
The Role of Sclerostin in Bone Diseases
A journey to music learning: a practical guide from musical instruments to emotional expression

随便看看