Sunday, March 30, 2014

Regular Expression II

On the second part of the Assignment Two, we were required to write four module level functions. The first one is_regex, returns True if a given string s is a valid Regular Expression. When we first encountered the problem, we thought it was a piece of cake, until we realized that there were at least six different conditions we need to consider. The code was finished in about 80 lines, but it was a little bit messy. The second function is all_regex_permutations, returns a list of possible valid regular expressions that a given sting s and its permutations can be. The difficulty was mainly on part one since we already have some code from the Professor during the lecture that deal with string permutations. All we need to do is generating all the permutations and checking which of them are valid expressions. The third one is regex_match, which is also the hardest one to implement. It returns True if the given string s matches the given regular expression r. The intuition was similar to is_regex, however, there were some minor details that need to be noticed. The last one was to build a regex tree when giving a valid regular expression. It was not that hard if you can finish the first three.

No comments:

Post a Comment