Week 11
Challenging REs
问题
Construct a regular expression for each of the following languages over the binary alphabet or prove that no such regular expression is possible:
- All strings except 11 or 111.
- Strings with 1 in every odd-number bit position.
- Strings with an equal number of 0s and 1s.
- Strings with at least two 0s and at most one 1.
- Strings that when interpreted as a binary integer are a multiple of 3.
- Strings with no two consecutive 1s.
- Strings that are palindromes (same forwards and backwards).
- Strings with an equal number of substrings of the form 01 and 10.
分析
- (1|1111*)
- (1.)*
- NOT POSSIBLE(RE的核心性质是根据当前字符实现状态转化,而非记录长度保存整个字符串的信息)
- ([02-9]*0[02-9]*0[02-9]*1[02-9]*)|([02-9]*0[02-9]*1[02-9]*0[02-9]*)|([02-9]*1[02-9]*0[02-9]*0[