Re: Regular Expression match

2010-09-24 Thread Vlastimil Brom
2010/9/25 AON LAZIO : > Hi, >    Say I have >    p = re.compile('a|b') >    text = 'a' >    d = p.findall(text) >    #d -> ['a'] >    What is the way to find out which pattern p match (the former or latter)? > I mean without knowing the outcome of p.findall >    Thanks > > -- > Aonlazio > '

Regular Expression match

2010-09-24 Thread AON LAZIO
Hi, Say I have p = re.compile('a|b') text = 'a' d = p.findall(text) #d -> ['a'] What is the way to find out which pattern p match (the former or latter)? I mean without knowing the outcome of p.findall Thanks -- Aonlazio 'Peace is always the way.' NW -- http://mail.p

Re: Help on regular expression match

2005-09-24 Thread John J. Lee
"Johnny Lee" <[EMAIL PROTECTED]> writes: > Fredrik Lundh wrote: [...] > To the HTMLParser, there is another problem (take my code for example): > > import urllib > import formatter > parser = htmllib.HTMLParser(formatter.NullFormatter()) > parser.feed(urllib.urlopen(baseUrl).read()) > parser.clos

Re: Help on regular expression match

2005-09-24 Thread John J. Lee
"Fredrik Lundh" <[EMAIL PROTECTED]> writes: [...] > or, if you're going to parse HTML pages from many different sources, a > real parser: > > from HTMLParser import HTMLParser > > class MyHTMLParser(HTMLParser): > > def handle_starttag(self, tag, attrs): > if tag == "

Re: Help on regular expression match

2005-09-23 Thread Johnny Lee
Fredrik Lundh wrote: > ".*" gives the longest possible match (you can think of it as searching back- > wards from the right end). if you want to search for "everything until a > given > character", searching for "[^x]*x" is often a better choice than ".*x". > > in this case, I suggest using some

Re: Help on regular expression match

2005-09-22 Thread Fredrik Lundh
Johnny Lee wrote: > I've met a problem in match a regular expression in python. Hope > any of you could help me. Here are the details: > > I have many tags like this: > xxxhttp://xxx.xxx.xxx"; xxx>xxx > xx > xxxhttp://xxx.xxx.xxx"; xxx>xxx > . > And I want to find

Help on regular expression match

2005-09-22 Thread Johnny Lee
Hi, I've met a problem in match a regular expression in python. Hope any of you could help me. Here are the details: I have many tags like this: xxxhttp://xxx.xxx.xxx"; xxx>xxx xx xxxhttp://xxx.xxx.xxx"; xxx>xxx . And I want to find all the "http://xxx.xxx.

Re: regular expression match collection

2005-02-04 Thread [EMAIL PROTECTED]
Thanks you... -- http://mail.python.org/mailman/listinfo/python-list

Re: regular expression match collection

2005-02-04 Thread P
[EMAIL PROTECTED] wrote: Hello, For example I have a string : "Halo by by by" Then I want to take and know the possition of every "by" how can I do it in python? [ match.start() for match in p.finditer("Helo by by by") ] see: http://mail.python.org/pipermail/python-list/2004-December/255013.html --

Re: regular expression match collection

2005-02-04 Thread Steve Holden
[EMAIL PROTECTED] wrote: Hello, For example I have a string : "Halo by by by" Then I want to take and know the possition of every "by" how can I do it in python? I tried to use: p = re.compile(r"by") m = p.search("Helo by by by") print m.group() # result "by" print m.span() # result (5,7)

Re: regular expression match collection

2005-02-04 Thread Fredrik Lundh
<[EMAIL PROTECTED]> wrote: > For example I have a string : "Halo by by by" > Then I want to take and know the possition of every "by" > how can I do it in python? > > I tried to use: > > p = re.compile(r"by") > m = p.search("Helo by by by") > print m.group() # result "by" > print m.span() # r

regular expression match collection

2005-02-04 Thread [EMAIL PROTECTED]
Hello, For example I have a string : "Halo by by by" Then I want to take and know the possition of every "by" how can I do it in python? I tried to use: p = re.compile(r"by") m = p.search("Helo by by by") print m.group() # result "by" print m.span() # result (5,7) How can I get the inf

Re: Regular expression match objects - compact syntax?

2005-02-04 Thread Diez B. Roggisch
Johann C. Rocholl wrote: > > How do you people handle this? Usually we don't bothe too much. But it has been suggested to do something like this: class Matcher: def __init__(self, rex): self.rex = rex def match(self, s): self.m = self.rex.match(s) return not self.m

Regular expression match objects - compact syntax?

2005-02-03 Thread Johann C. Rocholl
Hello python-list, I have a question about the match objects that are returned from the match() method of compiled regular expression objects from the 're' module. To parse Postscript T1 fonts that were disassembled into plaintext, I came up with the following code: import re rmoveto = re.compile