Home > Programming > Regular Expressions in Python

Regular Expressions in Python

Here is the way of matching an expression in Python program. Its absolutely very easy to do this. All that you need to do is importing regular expression re and use re.search(pattern,string).  The below example gives a brief idea of how it is done.

#Author:Vasanth Raja Chittampally
import re
pat=raw_input("Enter the pattern:")
f=open('b.txt', 'r')
if match :
	print match.group()
	print 'pattern was not found'
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: