Regular expressions are really useful whenever you want to search for or replace text in a file or a string. That means, all the time! They are concise, elegant, powerful and simple. So let’s have a look to some examples.
I provide below a simple code example to show the usage of regular expressions in python.
left = r'\begin'
right = r''
This code returns:
Take care to the ‘r’ before the strings: they manage all the character escape subtleties for you (see http://docs.python.org/2/howto/regex.html for the explanations about the “backslash plague”)
If you want to master regex, have a look to O’Reilly books, they are amazing.