regex category archive

1 April 2008

Regex Walk-Through: Match filename base and extension

This post is a rather lengthy analysis of a short regular expression:

(.+?)(\.[^.]*$|$)

I’m continuing to enjoy and learn a lot from Jeffrey Friedl’s Mastering Regular Expressions. One of the things that works well for me is the way he walks through examples and iteratively builds a more robust pattern for a particular task. It helps to develop logical ways of thinking about these things.

While you may not need to accomplish the particular task described in this article, I hope you might benefit by following along with the explanation. (Although it’s probably not as clear and concise as the ones in MRE!)

So! I recently wanted to modify a filename by inserting some text before the extension and was pleased with the regular expression I built for …

29 March 2008

Python: Regex Test Function

 

More fun with Python and regular expressions. Following up on a previous post, I wanted to share a little test regex function I wrote in Python to help me as I work through the regular expression book.

I’m mostly working at the interactive prompt and had been running commands from Python re (the regex module) as I experimented with different regular expressions. This was good as I spent time in help(re) and built up some muscle memory for Python regex functions, but it was becoming repetitious to keep typing the commands for analyzing the results of a match. Once I started learning about writing functions in Python, I realized it was time to enhance my …

23 March 2008

Goals: Learning Python and Regular Expressions

I don’t want to go all 7 Habits of Highly Effective People on you, but I’ll say this: I think it’s good to have goals and to work towards your goals.

I like this quote, which I’ve seen attributed to Zig Ziglar:

“Most people fail to reach their goals not because their plans are too simple or too complicated. Most people don’t reach their goals because they’re not committed and willing to follow their plans.”

I think that’s very true. There are so many things I haven’t done because I didn’t follow through on a plan.

What this means for you, loyal reader, is that one of the reasons I’m not accomplishing the goal of writing more for the web site (including a write-up of …