For assignment 2 we have been tasked
with working on regular expressions, and regular expression trees.
Since I hadn't really heard anything about regular expressions I
decided to do some Googling before I began. Turns out, regular expressions are quite useful. They allow for matching a variety
of strings by simply using the correct expression. There are
different types and different languages that use regular expressions
but they are generally used in similar ways. They can be extremely
useful for pattern matching; for something simple like looking for
whitespace or even full sentences.
I spent some time struggling with the
first function that I was working on: is_regex() – which determines
whether or not a string is a valid regular expression. It is of
course a recursive function and really doesn't seem that difficult at
first glance, but there are some cases to consider which take a bit
more work. The challenge is basically to determine the proper amount
of nesting for parentheses inside a string. I tried a couple methods
which worked on some test cases but not all of them. I ended up using
a helper function to get what I needed done and it seemed like a
pretty clear solution so I'm happy with that.
I'm not very far into the rest of the
assignment so I better get to that and update about that next week!