Skip to main content

Posts

Showing posts with the label sub

Regular Expressions in Python

This session about Python Regular expressions how we can work with patterns and the specific methods available in re module. match() group(), groups() search() compile() sub() Regular expression sample in Python Here is the sample for match function use. #!/usr/bin/python """ This program illustrates the usage of match, group functions in re module This also shows how to use re flags """ import re line = "Python Orientation course helps professionals fish best opportunities" m = re.match( r'(.*) helps (.*?) .*', line, re.I) if m: print "m.group() : ", m.group() print "m.group(1) : ", m.group(1) print "m.group(2) : ", m.group(2) else: print "Don't have match!!" The output >>> execfile('c:/pybin/rematch.py') m.group() : Python Orientation course helps professionals fish best opportunities m.group(1) : Python Orientation course m.group(2) : ...