473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to match this text?

9
Hi,everyone!

I want to match <tr>...</tr> in my text file(exp.txt).

this is my python source code:
Expand|Select|Wrap|Line Numbers
  1. import re
  2.  
  3. f = open("exp.txt","r")
  4. str = f.read()
  5.  
  6. pat = re.compile("<tr>.*</tr>")
  7. m = pat.findall(str)
  8. print(m)
  9.  
but it didn't work,what should I do?
Attached Files
File Type: txt exp.txt (180 Bytes, 379 views)
Jul 14 '10 #1
2 1232
bvdet
2,851 Expert Mod 2GB
Try this pattern:
Expand|Select|Wrap|Line Numbers
  1. tag = "tr"
  2. patt = re.compile('<%s>(.+?)</%s>' % (tag,tag), re.S|re.M)
  3.  
Jul 14 '10 #2
sidooh
9
Thank you very much!

Sorry for my late reply
Jul 29 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: wooks | last post by:
I would appreciate some guidance not just to the solution but why my own solutions don't seem to work. Copy.xsl in the code below is an imported identity template. Non solution 1...
4
by: jmdaviault | last post by:
I want to do the equivalent of SELECT id from TABLE WHERE text='text' only fast solution I found is: SELECT id,text from TABLE WHERE MATCH(text) AGAINST('value' IN BOOLEAN MODE) HAVING...
32
by: Licheng Fang | last post by:
Basically, the problem is this: 'do' Python's NFA regexp engine trys only the first option, and happily rests on that. There's another example: 'oneself' The Python regular expression...
9
by: gregmcmullinjr | last post by:
Hello, I am new to the concept of XSL and am looking for some assistance. Take the following XML document: <binder> <author>Greg</author> <notes> <time>11:45</time>
5
by: Smokey Grindle | last post by:
Ok I must admit I stink at regular expressions... been trying to learn them for a while now and its not sticking how I wish it would... but I am trying to take a very long string (about 30KB) and...
2
by: =?Utf-8?B?Q2h1Y2sgUA==?= | last post by:
I am trying to retrieve the @AnswerCount Attribute for the @QuestionID=1 AND the Answer element text =3 I successfully can pass the variables QuestionID and Answer but can't pull out the...
8
by: nicolas.edel | last post by:
Hi, suppose i get the simple xml sample: <foo> 1 <bar>2</bar> 3 </foo> Now suppose i want to extract all the text of only the 'foo' node, ie
3
by: Happy Face | last post by:
Hi, All, I encountered this strange problem while using function preg_match. The following is the php code. when I set the line: $text = str_repeat('*', 12500); preg_match will return 0 for...
14
by: Andy B | last post by:
I need to create a regular expression that will match a 5 digit number, a space and then anything up to but not including the next closing html tag. Here is an example: <startTag>55555 any...
9
by: tgow | last post by:
Hi Everyone, I have the following XML: <input type ="Data"> <parameter name ="Name"> <variable type="Static"> <!]> </variable> ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.