Python: Regular expression

Posted: March 14, 2016 in Python

Hi, these are few example on my daily tasks using the regular expression in Python. The lists will be updated from time to time.

import re
text= "UPDATE `my_table` SET `col1` = '' WHERE `col_id` = '123456'"
searchObj = r"`col_id` = '\d+'",text, re.M|re.I)
if searchObj:
    print "Result : ",
    print "Nothing found!!"

The above code will print Result : col_id = ‘123456’


#Extract number from string

string = "test 123 test test"
mynumber = int('\d+', string).group())
print mynumber

You can download my python project at


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s