Wednesday, November 6, 2013

Regular Expressions

Our second assignment was the first time I had dealt with regular expressions. As always, I was looking forward to working with some new concepts after I had read through the assignment handout. A regular expression (regex for short) is a series of characters that can be interpreted by an appropriate class into a set of rules. These rules are used to determine if a string belongs to the regex, or if it doesn't. Other than a fun programming exercise, I didn't really see any practical applications of this. Turns out that regexes can be very useful in aiding the interpretation of a string. If you need your program to read files, but treat different types of strings in different ways, comparing sections of your file to a list of regexes can help you classify them for proper handling. Another use of regexes might be in detecting cheat codes in games. Instead of having a "Cheats" menu option, which would lead to a screen where the user can input codes in a textbox of some kind, consider continuously scanning the user input during normal gameplay. If a series of inputs matches the general "cheat code" regex, then said inputs can be compared to a list of cheats, and the appropriate one activated.

As far as the assignment itself, I was kind of disappointed. After scrambling within the last few days to get through the first assignment, I gave myself plenty of time to work on this one. The thing is, this assignment was easy. Once you understand the concept of regexes, and the set of rules described in the handout, the actual coding was fairly simple. The rules for the various operators were practically written in pseudo-code, ready to be translated into Python syntax. I feel kinda bad saying that, because I know there were many people who struggled with this assignment, but this is just my opinion. It is not my intention to make anyone feel inferior (because you aren't), I just wanna write a blog post =\

No comments:

Post a Comment