RegEx / computer theory - construct a regEx in alphabetical order

荒凉一梦 提交于 2019-12-02 20:03:09

问题


In my grammars - Computer theory class I am trying to create a regular expression in alphabetical order(a-z)

l = {a, b, x, y, z, i, o, u, e, c}

This is what i have come up with using the kleene closure

aeiou(x*, y*, z*, i*, o*, u* e*) 

With the kleene close * thats zero or more so that should force abceioxyz?

We have not been learning this type of form

[^abc]

am i on the right track?


回答1:


As far as I understand, you want to capture strings with the following format:

  • The string contains any number of a's, afterwards any number of b's, then any number of c's, and so on...

Let's consider a derived example: We want all strings consisting of 0 and 1 and that has all 0's before 1's: Therefore, we can simply write 0*1*. Now try to adapt the pattern for more complex alphabets.




回答2:


the word must be in alphabetical order, so if it contains any a's, they surely must be at the front. likewise, if it contains any b's , they must come after the a's, and nothing can come in between the a's and b's

so we have: a*b*...

and so a pattern emerges.



来源:https://stackoverflow.com/questions/7667838/regex-computer-theory-construct-a-regex-in-alphabetical-order

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!