Real-World Regular Expressions for Python

We’ve covered a lot of ground in this series of articles, so let’s now put it all together and work through a real-life application. A common task is to parse a Windows INI file, which are key/value pairs, separated into sections, something like this: [python] [Section 1] val1=hello world val2=42 [Section 2] val1=foo! [/python] Let’s […]

Read More

More About Python Regular Expressions

In the first part of this series, we looked at the basic syntax of regular expressions and some simple examples. In this part, we’ll take a look at some more advanced syntax and a few of the other features Python has to offer. Regular Expression Captured Groups So far, we’ve searched within a string using […]

Read More

Introduction to Python Regular Expressions

Searching within a string for another string is pretty easy in Python: [python] >>> str = ‘Hello, world’ >>> print(str.find(‘wor’)) 7 [/python] This is fine if we know exactly what we’re looking for, but what if we’re looking for something not so well-defined? For example, if we want to search for a year, then we […]

Read More

Python Unicode: Encode and Decode Strings (in Python 2.x)

Strings are among the most commonly used data types in Python, and there might be times when you want to (or have to) work with strings containing or entirely made up of characters outside of the standard ASCII set (e.g. characters with accents or other markings). Python 2.x provides a data type called a Unicode […]

Read More