Sunday, May 6, 2012

Python flavored regex

Don't expect all flavors of regular expressions to be the same. For example, one difference between Java and Python, Java allows "unions" of character class by nesting.

    [0-4[6-8]]

is the same as

    [0-46-8]

but Python's re module will only interpret the latter.

There is an alternative module on pypi called regex that may replace re, which handles nested sets.

No comments:

Post a Comment

Fork me on GitHub