Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Krzysztof Kowalczyk http://blog.kowalczyk.info

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Python regular expressions

How to match a simple stuff in python:
import re
rg = re.compile("delete change (\d+) ")
m = rg.match("l.cpp#21 - delete change 20007 (t")

Then:
>>> m.group(0)
'delete change 20007 '
>>> m.group(1)
'20007'


rg.search() is similar to rg.match(), but only matches things at the beginning of the string i.e. it would match "delete change 20 " but not "foo delete change 20 ".
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS