.*? fixed it. Every occurrence of the pattern is now affected, which
is what I want.
Thank you very much.
--
http://mail.python.org/mailman/listinfo/python-list
Python 3.1.2 (r312:79147, Oct 9 2010, 00:16:06)
[GCC 4.4.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> m="cccvlvlvlvnnnflfllffccclfnnnooo"
>>> pattern = re.compile(r'ccc[^n]*nnn')
>>> pattern.sub("||", m)
'||flfllff||ooo'
>>> # or, as
On 2010-11-30, goldtech wrote:
> Hi,
>
> say:
import re
> m="cccvlvlvlvnnnflfllffccclfnnnooo"
re.compile(r'ccc.*nnn')
rtt=.sub("||",m)
rtt
> '||ooo'
>
> The regex is eating up too much. What I want is every non-overlapping
> occurrence I think.
>
> so rtt would
--- On Tue, 11/30/10, goldtech wrote:
> From: goldtech
> Subject: regular expression help
> To: python-list@python.org
> Date: Tuesday, November 30, 2010, 9:17 AM
> The regex is eating up too much. What I want is every
> non-overlapping
> occurrence I think.
>
>
Hi,
say:
>>> import re
m="cccvlvlvlvnnnflfllffccclfnnnooo"
>>> re.compile(r'ccc.*nnn')
>>> rtt=.sub("||",m)
>>> rtt
'||ooo'
The regex is eating up too much. What I want is every non-overlapping
occurrence I think.
so rtt would be:
'||flfllff||ooo'
just like findall acts bu
On Apr 29, 11:49 am, Tim Chase wrote:
> On 04/29/2010 01:00 PM, goldtech wrote:
>
> > Trying to start out with simple things but apparently there's some
> > basics I need help with. This works OK:
> import re
> p = re.compile('(ab*)(sss)')
> m = p.match( 'absss' )
>
> f=r'abss'
On 04/29/2010 01:00 PM, goldtech wrote:
Trying to start out with simple things but apparently there's some
basics I need help with. This works OK:
import re
p = re.compile('(ab*)(sss)')
m = p.match( 'absss' )
f=r'abss'
f
'abss'
m = p.match( f )
m.group(0)
Traceback (most recent call last):
goldtech wrote:
Hi,
Trying to start out with simple things but apparently there's some
basics I need help with. This works OK:
import re
p = re.compile('(ab*)(sss)')
m = p.match( 'absss' )
m.group(0)
'absss'
m.group(1)
'ab'
m.group(2)
'sss'
...
But two questions:
How can I operate a regex
Le 29/04/2010 20:00, goldtech a écrit :
Hi,
Trying to start out with simple things but apparently there's some
basics I need help with. This works OK:
import re
p = re.compile('(ab*)(sss)')
m = p.match( 'absss' )
m.group(0)
'absss'
m.group(1)
'ab'
m.group(2)
'sss'
...
But two questions:
Ho
Hi,
Trying to start out with simple things but apparently there's some
basics I need help with. This works OK:
>>> import re
>>> p = re.compile('(ab*)(sss)')
>>> m = p.match( 'absss' )
>>> m.group(0)
'absss'
>>> m.group(1)
'ab'
>>> m.group(2)
'sss'
...
But two questions:
How can I operate a regex
Jean-Claude Neveu wrote:
Hello,
I was wondering if someone could tell me where I'm going wrong with my
regular expression. I'm trying to write a regexp that identifies whether
a string contains a correctly-formatted currency amount. I want to
support dollars, UK pounds and Euros, but the exam
On Apr 12, 2:19 pm, ru...@yahoo.com wrote:
> On Apr 11, 9:42 pm, Jean-Claude Neveu
> wrote:
>
> > My regexp that I'm matching against is: "^\$\£?\d{0,10}(\.\d{2})?$"
>
> > Here's how I think it should work (but clearly
> > I'm wrong, because it does not actually work):
>
> > ^\$\£? Require ze
On Apr 11, 9:42 pm, Jean-Claude Neveu
wrote:
> My regexp that I'm matching against is: "^\$\£?\d{0,10}(\.\d{2})?$"
>
> Here's how I think it should work (but clearly
> I'm wrong, because it does not actually work):
>
> ^\$\£? Require zero or one instance of $ or £ at the start of the string.
Hello,
I was wondering if someone could tell me where
I'm going wrong with my regular expression. I'm
trying to write a regexp that identifies whether
a string contains a correctly-formatted currency
amount. I want to support dollars, UK pounds and
Euros, but the example below deliberately o
is BeautifulSoup really better? Since I don't know either I would prefer to
learn only one for now.
Thanks
Vincent Davis
On Tue, Jan 27, 2009 at 10:39 AM, MRAB wrote:
> Vincent Davis wrote:
>
>> I think there are two parts to this question and I am sure lots I am
>> missing. I am hoping an exa
Vincent Davis wrote:
I think there are two parts to this question and I am sure lots I am
missing. I am hoping an example will help me
I have a html doc that I am trying to use regular expressions to get a
value out of.
here is an example or the line
Parcel ID: 39-034-15-009
I want to get the
I think there are two parts to this question and I am sure lots I am
missing. I am hoping an example will help meI have a html doc that I am
trying to use regular expressions to get a value out of.
here is an example or the line
Parcel ID: 39-034-15-009
I want to get the number "39-034-15-009" aft
I think there are two parts to this question and I am sure lots I am
missing. I am hoping an example will help meI have a html doc that I am
trying to use regular expressions to get a value out of.
here is an example or the line
Parcel ID: 39-034-15-009
I want to get the number "39-034-15-009" aft
On Sat, Sep 27, 2008 at 1:58 PM, Fredrik Lundh <[EMAIL PROTECTED]>wrote:
> [EMAIL PROTECTED] wrote:
>
> import re
>>
>> fd = open(file, 'r')
>> line = fd.readline
>> pat1 = re.compile("\#*")
>>while(line):
>>mat1 = pat1.search(line)
>>if mat1:
>>
[EMAIL PROTECTED] wrote:
import re
fd = open(file, 'r')
line = fd.readline
pat1 = re.compile("\#*")
while(line):
mat1 = pat1.search(line)
if mat1:
print line
line = fd.readline()
I strongly doubt that this is
Hi,
Can some help me with the regular expression. I'm looking to search #
character in my file?
My file has contents:
###
Hello World
###
length = 10
breadth = 20
height = 30
###
##
On Fri, 18 Jul 2008 10:04:29 -0400, Russell Blau wrote:
> values = {}
> for expression in line.split(" "):
> if "=" in expression:
> name, val = expression.split("=")
> values[name] = val
> […]
>
> And when you get to be a really hard-core Pythonista, you could write
> the whol
On Jul 18, 3:35 pm, Nick Dumas <[EMAIL PROTECTED]> wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> I think you're over-complicating this. I'm assuming that you're going to
> do a line graph of some sorta, and each new line of the file contains a
> new set of data.
>
> The problem you m
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
I think you're over-complicating this. I'm assuming that you're going to
do a line graph of some sorta, and each new line of the file contains a
new set of data.
The problem you mentioned with your regex returning a match object
rather than a string i
[EMAIL PROTECTED] wrote:
Hello,
I am new to Python, with a background in scientific computing. I'm
trying to write a script that will take a file with lines like
c afrac=.7 mmom=0 sev=-9.56646 erep=0 etot=-11.020107 emad=-3.597647
3pv=0
extract the values of afrac and etot and plot them. I'm r
[EMAIL PROTECTED] wrote:
Hello,
I am new to Python, with a background in scientific computing. I'm
trying to write a script that will take a file with lines like
c afrac=.7 mmom=0 sev=-9.56646 erep=0 etot=-11.020107 emad=-3.597647
3pv=0
extract the values of afrac and etot...
Why not just sp
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I am new to Python, with a background in scientific computing. I'm
> trying to write a script that will take a file with lines like
>
> c afrac=.7 mmom=0 sev=-9.56646 erep=0 etot=-11.020107 emad=-3.597647
> 3pv=0
>
> extract the values
Hello,
I am new to Python, with a background in scientific computing. I'm
trying to write a script that will take a file with lines like
c afrac=.7 mmom=0 sev=-9.56646 erep=0 etot=-11.020107 emad=-3.597647
3pv=0
extract the values of afrac and etot and plot them. I'm really
struggling with getti
"santhosh kumar" <[EMAIL PROTECTED]> wrote:
> I have text like ,
> STRINGTABLE
> BEGIN
> ID_NEXT_PANE"Cambiar a la siguiente sección de laventana
> \nSiguiente sección"
> ID_PREV_PANE"Regresar a la sección anterior de
> laventana\nSección anterior"
> END
> STRI
Hi all,
I have text like ,
STRINGTABLE
BEGIN
ID_NEXT_PANE"Cambiar a la siguiente sección de laventana
\nSiguiente sección"
ID_PREV_PANE"Regresar a la sección anterior de
laventana\nSección anterior"
END
STRINGTABLE
BEGIN
ID_VIEW_TOOLBAR "Mostrar u oculta
On Feb 27, 6:28 am, [EMAIL PROTECTED] wrote:
> Hi All,
>
> I have a python utility which helps to generate an excel file for
> language translation. For any new language, we will generate the excel
> file which will have the English text and column for interested
> translation language. The transla
Hi All,
I have a python utility which helps to generate an excel file for
language translation. For any new language, we will generate the excel
file which will have the English text and column for interested
translation language. The translator will provide the language string
and again I will h
python regular expression help
En Wed, 11 Apr 2007 23:14:01 -0300, Qilong Ren <[EMAIL PROTECTED]>
escribió:
> Thanks for reply. That actually is not what I want. Strings I am dealing
> with may look like this:
> s = 'a = 4.5 b = 'h' 'd' c = 4.5 3.5'
On Apr 11, 11:15 pm, [EMAIL PROTECTED] wrote:
> On Apr 11, 9:50 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
> lhs = re.compile(r'\s*(\b\w+\s*=)')
> for s in [ "a = 4 b =3.4 5.4 c = 4.5",
> "a = 4.5 b = 'h' 'd' c = 4.5 3.5"]:
> tokens = lhs.split(s)
> results = [tokens[_] + tokens[_+1] for
On Apr 11, 11:50 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Wed, 11 Apr 2007 23:14:01 -0300, Qilong Ren <[EMAIL PROTECTED]>
> escribió:
>
> > Thanks for reply. That actually is not what I want. Strings I am dealing
> > with may look like this:
> > s = 'a = 4.5 b = 'h' 'd' c =
On Apr 11, 9:50 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Wed, 11 Apr 2007 23:14:01 -0300, Qilong Ren <[EMAIL PROTECTED]>
> escribió:
>
> > Thanks for reply. That actually is not what I want. Strings I am dealing
> > with may look like this:
> > s = 'a = 4.5 b = 'h' 'd' c = 4.5
On Apr 11, 10:50 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Wed, 11 Apr 2007 23:14:01 -0300, Qilong Ren <[EMAIL PROTECTED]>
> escribió:
>
> > Thanks for reply. That actually is not what I want. Strings I am dealing
> > with may look like this:
> > s = 'a = 4.5 b = 'h' 'd' c =
mes = re.compile(r'(\w+)\s*=').findall(s)
the corresponding values
values = re.split(r'\w+\s*=',s)[1:]
It dose not look good but it works. What do you think?
Thanks,Qilong
- Original Message
From: 7stud <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Sent: Wedn
En Wed, 11 Apr 2007 23:14:01 -0300, Qilong Ren <[EMAIL PROTECTED]>
escribió:
> Thanks for reply. That actually is not what I want. Strings I am dealing
> with may look like this:
> s = 'a = 4.5 b = 'h' 'd' c = 4.5 3.5'
> What I want is
> a = 4.5
> b = 'h' 'd'
> c = 4.5 3.5
On Apr 11, 7:41 pm, liupeng <[EMAIL PROTECTED]> wrote:
> pattern = re.compile(r'\w+\s*=\s*[0-9]*.[0-9]*\s*')
> lists = pattern.findall(s)
> print lists
> ['a=4 ', 'b=3.4 ', 'c=4.5']
>
> On Wed, Apr 11, 2007 at 06:10:07PM -0700, Qilong Ren wrote:
> > Hi, everyone,
>
> > I am extracting some informat
From: liupeng <[EMAIL PROTECTED]>
To: python-list@python.org
Sent: Wednesday, April 11, 2007 6:41:30 PM
Subject: Re: python regular expression help
pattern = re.compile(r'\w+\s*=\s*[0-9]*.[0-9]*\s*')
lists = pattern.findall(s)
print lists
['a=4 ', 'b=3.4 ', 'c=
pattern = re.compile(r'\w+\s*=\s*[0-9]*.[0-9]*\s*')
lists = pattern.findall(s)
print lists
['a=4 ', 'b=3.4 ', 'c=4.5']
On Wed, Apr 11, 2007 at 06:10:07PM -0700, Qilong Ren wrote:
> Hi, everyone,
>
> I am extracting some information from a given string using python RE. The
> string is ,for example,
Hi, everyone,
I am extracting some information from a given string using python RE. The
string is ,for example,
s = 'a = 4 b =3.4 5.4 c = 4.5'
What I want is :
a = 4
b = 3.4 5.4
c = 4.5
Right now I use :
pattern = re.compile(r'\w+\s*=\s*.*?\s+')
lists = pattern.findall(s)
It
[EMAIL PROTECTED] wrote:
> Hello,
>
> I am having some difficulty creating a regular expression for the
> following string situation in html. I want to find a table that has
> specific text in it and then extract the html just for that immediate
> table.
>
> the string would look something like th
[EMAIL PROTECTED] skrev:
> Hello,
>
> I am having some difficulty creating a regular expression for the
> following string situation in html. I want to find a table that has
> specific text in it and then extract the html just for that immediate
> table.
>
> the string would look something like t
Hi Steve,
[EMAIL PROTECTED] wrote:
> I am having some difficulty creating a regular expression for the
> following string situation in html. I want to find a table that has
> specific text in it and then extract the html just for that immediate
> table.
Any reason why you can't use a real HTML pa
Hello,
I am having some difficulty creating a regular expression for the
following string situation in html. I want to find a table that has
specific text in it and then extract the html just for that immediate
table.
the string would look something like this:
...stuff here...
...stuff here...
On 10/8/06, Roy Smith <[EMAIL PROTECTED]> wrote:
> "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> > Certainly true, and it always gives me a hard time because I don't know
> > to which extend a regular expression nowadays might do the job because
> > of these extensions. It was so much easier back
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Certainly true, and it always gives me a hard time because I don't know
> to which extend a regular expression nowadays might do the job because
> of these extensions. It was so much easier back in the old times
What old times? I've been working
Fredrik Lundh wrote:
> it's slightly faster, but both your alternatives are about 10x slower
> than a straightforward:
> def balanced(txt):
> return txt.count("(") == txt.count(")")
I know, but if you read my post again you see that I have shown those
solutions to mark ")))(((" as bad expres
Mirco Wahab schrieb:
> Thus spoke Diez B. Roggisch (on 2006-10-08 10:49):
>> Certainly true, and it always gives me a hard time because I don't know
>> to which extend a regular expression nowadays might do the job because
>> of these extensions. It was so much easier back in the old times
>
>
Thus spoke Diez B. Roggisch (on 2006-10-08 10:49):
> Certainly true, and it always gives me a hard time because I don't know
> to which extend a regular expression nowadays might do the job because
> of these extensions. It was so much easier back in the old times
Right, in perl, this would be
[EMAIL PROTECTED] wrote:
> The dict solution looks better, but this may be faster:
it's slightly faster, but both your alternatives are about 10x slower
than a straightforward:
def balanced(txt):
return txt.count("(") == txt.count(")")
--
http://mail.python.org/mailman/listinfo/python
Tim Chase:
> It still doesn't solve the aforementioned problem
> of things like ')))(((' which is balanced, but psychotic. :)
This may solve the problem:
def balanced(txt):
d = {'(':1, ')':-1}
tot = 0
for c in txt:
tot += d.get(c, 0)
if tot < 0:
return Fal
On 8 Oct 2006 01:49:50 -0700, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> Even if it has - I'm not sure if it really does you good, for several
> reasons:
>
> - regexes - even enhanced ones - don't build trees. But that is what
> you ultimately want
>from an expression like sin(log(x))
>
>
hanumizzle wrote:
> On 7 Oct 2006 15:00:29 -0700, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> >
> > Chris wrote:
> > > I need a pattern that matches a string that has the same number of '('
> > > as ')':
> > > findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = [
> > > '((2x+2)si
> Why does it need to be a regex? There is a very simple and well-known
> algorithm which does what you want.
>
> Start with i=0. Walk the string one character at a time, incrementing i
> each time you see a '(', and decrementing it each time you see a ')'. At
> the end of the string, the co
In article <[EMAIL PROTECTED]>,
"Chris" <[EMAIL PROTECTED]> wrote:
> I need a pattern that matches a string that has the same number of '('
> as ')':
> findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = [
> '((2x+2)sin(x))', '(log(2)/log(5))' ]
> Can anybody help me out?
>
> Tha
On 7 Oct 2006 15:00:29 -0700, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
>
> Chris wrote:
> > I need a pattern that matches a string that has the same number of '('
> > as ')':
> > findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = [
> > '((2x+2)sin(x))', '(log(2)/log(5))' ]
> > C
Chris wrote:
> I need a pattern that matches a string that has the same number of '('
> as ')':
> findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = [
> '((2x+2)sin(x))', '(log(2)/log(5))' ]
> Can anybody help me out?
>
No, there is so such pattern. You will have to code up a func
Chris wrote:
> I need a pattern that matches a string that has the same number of '('
> as ')':
> findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = [
> '((2x+2)sin(x))', '(log(2)/log(5))' ]
> Can anybody help me out?
This is not possible with regular expressions - they can't "re
I need a pattern that matches a string that has the same number of '('
as ')':
findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = [
'((2x+2)sin(x))', '(log(2)/log(5))' ]
Can anybody help me out?
Thanks for any help!
--
http://mail.python.org/mailman/listinfo/python-list
Edward Elliott wrote:
> [EMAIL PROTECTED] wrote:
>> If you are parsing HTML, it may make more sense to use a package
>> designed especially for that purpose, like Beautiful Soup.
>
> I don't know Beautiful Soup, but one advantage regexes have over some
> parsers is handling malformed html.
Beaut
Edward Elliott <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
>> If you are parsing HTML, it may make more sense to use a package
>> designed especially for that purpose, like Beautiful Soup.
>
> I don't know Beautiful Soup, but one advantage regexes have over some
> parsers is handling ma
[EMAIL PROTECTED] wrote:
> If you are parsing HTML, it may make more sense to use a package
> designed especially for that purpose, like Beautiful Soup.
I don't know Beautiful Soup, but one advantage regexes have over some
parsers is handling malformed html. Omitted closing tags can wreak havoc.
Interesting... thank you.
--
http://mail.python.org/mailman/listinfo/python-list
r']*>(.*?)'
With a slight modification that did exactly what I wanted, and yes the
findall was the only way to get all that I needed as I buffered all the
read.
Thanks a bunch.
--
http://mail.python.org/mailman/listinfo/python-list
If what you need is "simple," regular expressions are almost never the
answer. And how simple can it be if you are posting here? :)
BeautifulSoup isn't all that hard. Observe:
>>> from BeautifulSoup import BeautifulSoup
>>> html = '10:00am - 11:00am: >> href="/tvpdb?d=tvp&id=167540528&[snip]>T
I considered that but what I need is simple and I don't want to use
another library for something so simple but thank you. Plus I don't
understand them all that well :)
--
http://mail.python.org/mailman/listinfo/python-list
If you are parsing HTML, it may make more sense to use a package
designed especially for that purpose, like Beautiful Soup.
--
http://mail.python.org/mailman/listinfo/python-list
Great I will test this out once I have the time... thanks for the quick
response
--
http://mail.python.org/mailman/listinfo/python-list
RunLevelZero wrote:
> 10:00am - 11:00am:
> Here is the re.
>
> findshows =
> re.compile(r'(\d\d:\d\d\D\D\s-\s\d\d:\d\d\D\D:*.*)')
1. A regex remembers everything it matches -- no need to wrap the entire
thing in parens. Just call group() on the returned MatchObject.
2. If all you want is the
I have some data and I need to put it in a list in a particular way. I
have that figured out but there is " stuff " in the data that I don't
want.
Example:
10:00am - 11:00am: The
Price Is Right
All I want is " Price Is Right "
Here is the re.
findshows =
re.compile(r'(\d\d:\d\d\D\D\s-\s\d\d:\
73 matches
Mail list logo