Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
由其描述给出的常规语言:
{0,1, a} 的所有字符串的集合,其中包含子字符串 '01a' 和偶数个 '1'。例如,“01a1”、“101a”、“101a101”。
如何构造一个指定语言的正则表达式?
一个单行机,真是太棒了:
^([0a]*1[0a]*([0a]*1[0a]*1)*)01a([0a]*1[0a]*1)*|([0a]*1[0a]*1)*01a([0a]*1[0a]*([0a]*1[0a]*1)*)$
基本上,它检查
奇数个 1 的字符串 + 01a + 偶数个 1 的字符串
或者
偶数个 1 的字符串 + 01a + 奇数个 1 的字符串