PythonLibraryReference, [http://www.python.org/doc/current/lib/module-re.html 4.2 re module]
PythonLibraryReference, [http://www.python.org/doc/current/lib/re-syntax.html 4.2.1 Regular Expression Syntax]
You can search or match.
search -- find something anywhere in the string, and return it
match -- find something from the beginning of the string, and return it
You can also split on a pattern.
For example:
...which produces:
["This is a ", "((test))", " of the ", "((emergency broadcasting station.))" ]
Compiling
If you use a regex a lot, compile it first.
Consider:
...which outputs: ('h1', 'robot', 'h1')
If you were going to do that match a lot, you could compile it, like so:
...which yields the same result.
I don't know how much faster compiled forms are than non-compiled forms.
Links
[http://www.amk.ca/python/howto/regex/ Regular Expression HOWTO] - excellent Python-based regular expression tutorial, by [http://www.amk.ca/ A.M. Kuchling.]