PDA

Click to See Complete Forum and Search --> : [RESOLVED] Regex in python


mar_zim
Oct 5th, 2006, 09:36 PM
Hi guys good day. First time to touch Python and i'm stuck in regex. Honestly speaking i'm no good in regex, so I need help about this one.

so far this is my code.

import re
micro_list = open('c:/my documents/my sample project/mhtbuilder_demo/bin/msdnlibrary.mht','r+b')

m = re.search('(?<=[<table class=3D"data">])\w+',micro_list)
if m:
print m.group(0)



I want to get on what's between <table class=3D"data"> </table>. so far the pattern lacks </table> so basically I just get data after <table class=3D"data"> pattern because I don't on how to deal that one.:(

thanx in advance guys.

mar_zim
Oct 6th, 2006, 04:15 AM
Never mind I got it. :D

import re
samlist = open('sampletxt.txt','r+b')
m = samlist.read()
p = re.search('<table class=3D"data">(.*)</TABLE>',m,re.DOTALL)
if p:
print p.group(0)
else:
print 'no match'

samlist.close()