parik parik - 10 months ago 40
Python Question

How to deal with Regular expression in python?

I want to detect this format in my text file "1-321231", i mean any digit, plus '-',plus any digit,
i write this regular expression:


but i don't know how use it in python.


"Detect" is what we call "Match". Here is a working example of how to use it:

import re
string = '1-321231'
pattern = '\d[-]\d*'
match =, string)
if match:
    print 'we\'ve got a match!'