Re: regex help

2015-03-13 Thread Steven D'Aprano
Larry Martell wrote: > I need to remove all trailing zeros to the right of the decimal point, > but leave one zero if it's whole number. def strip_zero(s): if '.' not in s: return s s = s.rstrip('0') if s.endswith('.'): s += '0' return s And in use: py> strip_

Re: regex help

2015-03-13 Thread Cameron Simpson
On 13Mar2015 12:05, Larry Martell wrote: I need to remove all trailing zeros to the right of the decimal point, but leave one zero if it's whole number. For example, if I have this: 14S,5.,4.5686274500,3.7272727272727271,3.3947368421052630,5.7307692307692308,5.75471698113207

Re: regex help

2015-03-13 Thread Larry Martell
On Fri, Mar 13, 2015 at 1:29 PM, MRAB wrote: > On 2015-03-13 16:05, Larry Martell wrote: >> >> I need to remove all trailing zeros to the right of the decimal point, >> but leave one zero if it's whole number. For example, if I have this: >> >> >> 14S,5.,4.5686274500,3.72727272

Re: regex help

2015-03-13 Thread Tim Chase
On 2015-03-13 12:05, Larry Martell wrote: > I need to remove all trailing zeros to the right of the decimal > point, but leave one zero if it's whole number. > > But I can't figure out how to get the 5. to be 5.0. > I've been messing with the negative lookbehind, but I haven't fou

Re: regex help

2015-03-13 Thread MRAB
On 2015-03-13 16:05, Larry Martell wrote: I need to remove all trailing zeros to the right of the decimal point, but leave one zero if it's whole number. For example, if I have this: 14S,5.,4.5686274500,3.7272727272727271,3.3947368421052630,5.7307692307692308,5.75471698113207

Re: regex help

2015-03-13 Thread Thomas 'PointedEars' Lahn
Larry Martell wrote: > I need to remove all trailing zeros to the right of the decimal point, > but leave one zero if it's whole number. For example, if I have this: > > 14S,5.,4.5686274500,3.7272727272727271,3.3947368421052630,5.7307692307692308,5.7547169811320753,4.94230769

Re: regex help: splitting string gets weird groups

2010-04-08 Thread Patrick Maupin
On Apr 8, 3:40 pm, gry wrote: > >    >>> s='555tHe-rain.in#=1234' > >    >>> import re > >    >>> r=re.compile(r'([a-zA-Z]+|\d+|.)') > >    >>> r.findall(s) > >    ['555', 'tHe', '-', 'rain', '.', 'in', '#', '=', '1234'] > > This is nice and simple and has the invertible property that Patrick > me

Re: regex help: splitting string gets weird groups

2010-04-08 Thread gry
>    >>> s='555tHe-rain.in#=1234' >    >>> import re >    >>> r=re.compile(r'([a-zA-Z]+|\d+|.)') >    >>> r.findall(s) >    ['555', 'tHe', '-', 'rain', '.', 'in', '#', '=', '1234'] This is nice and simple and has the invertible property that Patrick mentioned above. Thanks much! -- http://mail.py

Re: regex help: splitting string gets weird groups

2010-04-08 Thread Jon Clements
On 8 Apr, 19:49, gry wrote: > [ python3.1.1, re.__version__='2.2.1' ] > I'm trying to use re to split a string into (any number of) pieces of > these kinds: > 1) contiguous runs of letters > 2) contiguous runs of digits > 3) single other characters > > e.g.   555tHe-rain.in#=1234   should give:  

Re: regex help: splitting string gets weird groups

2010-04-08 Thread gry
On Apr 8, 3:40 pm, MRAB wrote: ... > Group 1 and group 4 match '='. > Group 1 and group 3 match '1234'. > > If a group matches then any earlier match of that group is discarded, Wow, that makes this much clearer! I wonder if this behaviour shouldn't be mentioned in some form in the python docs?

Re: regex help: splitting string gets weird groups

2010-04-08 Thread Tim Chase
gry wrote: [ python3.1.1, re.__version__='2.2.1' ] I'm trying to use re to split a string into (any number of) pieces of these kinds: 1) contiguous runs of letters 2) contiguous runs of digits 3) single other characters e.g. 555tHe-rain.in#=1234 should give: [555, 'tHe', '-', 'rain', '.',

Re: regex help: splitting string gets weird groups

2010-04-08 Thread Patrick Maupin
On Apr 8, 1:49 pm, gry wrote: > [ python3.1.1, re.__version__='2.2.1' ] > I'm trying to use re to split a string into (any number of) pieces of > these kinds: > 1) contiguous runs of letters > 2) contiguous runs of digits > 3) single other characters > > e.g.   555tHe-rain.in#=1234   should give:

Re: regex help: splitting string gets weird groups

2010-04-08 Thread Jon Clements
On 8 Apr, 19:49, gry wrote: > [ python3.1.1, re.__version__='2.2.1' ] > I'm trying to use re to split a string into (any number of) pieces of > these kinds: > 1) contiguous runs of letters > 2) contiguous runs of digits > 3) single other characters > > e.g.   555tHe-rain.in#=1234   should give:  

Re: regex help: splitting string gets weird groups

2010-04-08 Thread MRAB
gry wrote: [ python3.1.1, re.__version__='2.2.1' ] I'm trying to use re to split a string into (any number of) pieces of these kinds: 1) contiguous runs of letters 2) contiguous runs of digits 3) single other characters e.g. 555tHe-rain.in#=1234 should give: [555, 'tHe', '-', 'rain', '.',

Re: Regex help needed!

2010-01-07 Thread Rolando Espinoza La Fuente
# http://gist.github.com/271661 import lxml.html import re src = """ lksjdfls kdjff lsdfs sdjfls sdfsdwelcome hello, my age is 86 years old and I was born in 1945. Do you know that PI is roughly 3.1443534534534534534 """ regex = re.compile('amazon_(\d+)') doc = lxml.html.document_fromstring(s

Re: Regex help needed!

2010-01-07 Thread Aahz
In article <19de1d6e-5ba9-42b5-9221-ed7246e39...@u36g2000prn.googlegroups.com>, Oltmans wrote: > >I've written this regex that's kind of working >re.findall("\w+\s*\W+amazon_(\d+)",str) > >but I was just wondering that there might be a better RegEx to do that >same thing. Can you kindly suggest a

Re: Regex help needed!

2009-12-24 Thread F.R.
On 21.12.2009 12:38, Oltmans wrote: Hello,. everyone. I've a string that looks something like lksjdfls kdjff lsdfs sdjflssdfsdwelcome > From above string I need the digits within the ID attribute. For example, required output from above string is - 35343433 - 345343 - 8898 I've w

Re: Regex help needed!

2009-12-22 Thread Paul McGuire
On Dec 21, 5:38 am, Oltmans wrote: > Hello,. everyone. > > I've a string that looks something like > > lksjdfls kdjff lsdfs sdjfls =   "amazon_35343433">sdfsdwelcome > > > From above string I need the digits within the ID attribute. For > example, required output from above string is

Re: Regex help needed!

2009-12-22 Thread Umakanth
how about re.findall(r'\w+.=\W\D+(\d+)?',str) ? this will work for any string within id ! ~Ukanth On Dec 21, 6:06 pm, Oltmans wrote: > On Dec 21, 5:05 pm, Umakanth wrote: > > > How about re.findall(r'\d+(?:\.\d+)?',str) > > > extracts only numbers from any string > > Thank you. However, I

Re: Regex help needed!

2009-12-21 Thread Johann Spies
> Oltmans wrote: > >I've a string that looks something like > > > >lksjdfls kdjff lsdfs sdjfls >= "amazon_35343433">sdfsdwelcome > > > > > >>From above string I need the digits within the ID attribute. For > >example, required output from above string is > >- 35343433 > >- 345343 > >-

Re: Regex help needed!

2009-12-21 Thread MRAB
Oltmans wrote: Hello,. everyone. I've a string that looks something like lksjdfls kdjff lsdfs sdjfls sdfsdwelcome From above string I need the digits within the ID attribute. For example, required output from above string is - 35343433 - 345343 - 8898 I've written this regex that

Re: Regex help needed!

2009-12-21 Thread Umakanth
Ok. how about re.findall(r'\w+_(\d+)',str) ? returns ['345343', '35343433', '8898', '8898'] ! On Dec 21, 6:06 pm, Oltmans wrote: > On Dec 21, 5:05 pm, Umakanth wrote: > > > How about re.findall(r'\d+(?:\.\d+)?',str) > > > extracts only numbers from any string > > Thank you. However, I only

Re: Regex help needed!

2009-12-21 Thread Oltmans
On Dec 21, 5:05 pm, Umakanth wrote: > How about re.findall(r'\d+(?:\.\d+)?',str) > > extracts only numbers from any string > Thank you. However, I only need the digits within the ID attribute of the DIV. Regex that you suggested fails on the following string lksjdfls kdjff lsdfs sdjfl

Re: Regex help needed!

2009-12-21 Thread Peter Otten
Oltmans wrote: > I've a string that looks something like > > lksjdfls kdjff lsdfs sdjfls = "amazon_35343433">sdfsdwelcome > > > From above string I need the digits within the ID attribute. For > example, required output from above string is > - 35343433 > - 345343 > - 8898 > > I'v

Re: Regex help needed!

2009-12-21 Thread mik3
On Dec 21, 7:38 pm, Oltmans wrote: > Hello,. everyone. > > I've a string that looks something like > > lksjdfls kdjff lsdfs sdjfls =   "amazon_35343433">sdfsdwelcome > > > From above string I need the digits within the ID attribute. For > example, required output from above string is

Re: Regex help needed!

2009-12-21 Thread Umakanth
How about re.findall(r'\d+(?:\.\d+)?',str) extracts only numbers from any string ~uk On Dec 21, 4:38 pm, Oltmans wrote: > Hello,. everyone. > > I've a string that looks something like > > lksjdfls kdjff lsdfs sdjfls =   "amazon_35343433">sdfsdwelcome > > > From above string I n

Re: regex help

2009-12-17 Thread S.Selvam
On Wed, Dec 16, 2009 at 10:46 PM, Gabriel Rossetti < gabriel.rosse...@arimaz.com> wrote: > Hello everyone, > > I'm going nuts with some regex, could someone please show me what I'm doing > wrong? > > I have an XMPP msg : > > > > > 123 > 456 > > ... >

Re: regex help

2009-12-16 Thread Intchanter / Daniel Fackrell
On Dec 16, 10:22 am, r0g wrote: > Gabriel Rossetti wrote: > > Hello everyone, > > > I'm going nuts with some regex, could someone please show me what I'm > > doing wrong? > > > I have an XMPP msg : > > > > > Does someone know what is wrong with my expression? Thank you, Gabriel > > Gabriel, tryin

Re: regex help

2009-12-16 Thread r0g
Gabriel Rossetti wrote: > Hello everyone, > > I'm going nuts with some regex, could someone please show me what I'm > doing wrong? > > I have an XMPP msg : > > > > Does someone know what is wrong with my expression? Thank you, Gabriel Gabriel, trying to debug a long regex in situ can be a

Re: regex help

2009-07-09 Thread Peter Otten
David wrote: >   > > Open: > > 5.50 > >   > Mkt Cap: > > 6.92M > >   > P/E: > > 21.99 > > > > I want to extract the open, mkt cap and P/E values - but apart from > doing loads of indivdual REs which I think would look messy, I can't > think of a better and neater looking way. Any ideas?

Re: regex help

2009-07-08 Thread Rhodri James
On Wed, 08 Jul 2009 23:06:22 +0100, David wrote: Hi I have a few regexs I need to do, but im struggling to come up with a nice way of doing them, and more than anything am here to learn some tricks and some neat code rather than getting an answer - although thats obviously what i would like

Re: regex help

2009-07-08 Thread Tim Harig
On 2009-07-08, Chris Rebert wrote: > On Wed, Jul 8, 2009 at 3:06 PM, David wrote: >> I want to extract the open, mkt cap and P/E values - but apart from >> doing loads of indivdual REs which I think would look messy, I can't >> think of a better and neater looking way. Any ideas? You are download

Re: regex help

2009-07-08 Thread Chris Rebert
On Wed, Jul 8, 2009 at 3:06 PM, David wrote: > Hi > > I have a few regexs I need to do, but im struggling to come up with a > nice way of doing them, and more than anything am here to learn some > tricks and some neat code rather than getting an answer - although > thats obviously what i would like

RE: Regex Help

2008-09-25 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Support Desk wrote: > Thanks for the reply ... A: The vulture doesn't get Frequent Poster miles. Q: What's the difference between a top-poster and a vulture? -- http://mail.python.org/mailman/listinfo/python-list

RE: Regex Help

2008-09-24 Thread Support Desk
Thanks for the reply, I found out the problem was occurring later on in the script. The regexp works well. -Original Message- From: Lawrence D'Oliveiro [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 23, 2008 6:51 PM To: python-list@python.org Subject: Re: Regex Help In me

Re: Regex Help

2008-09-23 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Support Desk wrote: > Anybody know of a good regex to parse html links from html code? The one I > am currently using seems to be cutting off the last letter of some links, > and returning links like > > http://somesite.co > > or http://somesite.ph > > the code I

Re: Regex Help

2008-09-23 Thread Miki
Hello, > Anybody know of a good regex to parse html links from html code? BeautifulSoup is *the* library to handle HTML from BeautifulSoup import BeautifulSoup from urllib import urlopen soup = BeautifulSoup(urlopen("http://python.org/";)) for a in soup("a"): print a["href"] HTH, -- Miki <[

Re: Regex Help

2008-09-22 Thread Fredrik Lundh
Support Desk wrote: the code I am using is regex = r'' that's way too fragile to work with real-life HTML (what if the link has a TITLE attribute, for example? or contains whitespace after the HREF?) you might want to consider using a real HTML parser for this task. page_text = urllib.

RE: regex help

2008-06-30 Thread Metal Zong
>>> import re >>> >>> if __name__ == "__main__": ... lst = [281, 713, 832, 1281, 1713, 1832, 2281, 2713, 2832] ... for item in lst: ... if re.match("^1?(?=281)|^1?(?=713)|^1?(?=832)", str(item)): ... print "%d invalid" % item ... else: ... print "%d v

Re: regex help

2008-06-30 Thread Cédric Lucantis
Le Monday 30 June 2008 16:53:54 Support Desk, vous avez écrit : > Hello, >I am working on a web-app, that querys long distance numbers from a > database of call logs. I am trying to put together a regex that matches any > number that does not start with the following. Basically any number that

RE: regex help

2008-06-03 Thread Support Desk
That’s it exactly..thx -Original Message- From: Reedick, Andrew [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 03, 2008 9:26 AM To: Support Desk Subject: RE: regex help The regex will now skip anything with an '@'in the filename on the assumption it's already in the

RE: regex help

2008-06-03 Thread Reedick, Andrew
> From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > On Behalf Of Support Desk > Sent: Tuesday, June 03, 2008 9:32 AM > To: python-list@python.org > Subject: regex help > > I am trying to put together a regular expression that will > rename users address books on our server due to a recent >

Re: Regex help...pretty please?

2006-08-23 Thread vbgunz
MooMaster Wrote: > I'm trying to develop a little script that does some string > manipulation. I have some few hundred strings that currently look like > this: > cond(a,b,c) > and I want them to look like this: > cond(c,a,b) I zoned out on your question and created a very simple flipper. Although

Re: Regex help...pretty please?

2006-08-23 Thread Paul McGuire
"MooMaster" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'm trying to develop a little script that does some string > manipulation. I have some few hundred strings that currently look like > this: > > cond(a,b,c) > > and I want them to look like this: > > cond(c,a,b) Pyparsing

Re: Regex help...pretty please?

2006-08-23 Thread Simon Forman
MooMaster wrote: > I'm trying to develop a little script that does some string > manipulation. I have some few hundred strings that currently look like > this: > > cond(a,b,c) > > and I want them to look like this: > > cond(c,a,b) > > but it gets a little more complicated because the conds themselv

Re: Regex help...pretty please?

2006-08-23 Thread Tim Chase
> cond(a,b,c) > > and I want them to look like this: > > cond(c,a,b) > > but it gets a little more complicated because the conds themselves may > have conds within, like the following: > > cond(0,cond(c,cond(e,cond(g,h,(ahttp://mail.python.org/mailman/listinfo/python-list

Re: regex help

2006-05-16 Thread johnzenger
Why not use split instead of regular expressions? >>> ln = "3232 23 9 9 - 9 9 - 911 >>> 110" >>> ln.split() ['32', '32', '23', '9', '9', '-', '9', '9', '-', '9', '11', '1', '10'] Much simpler, yes? Just find the line that comes after a line that

Re: regex help

2006-05-16 Thread Peter Otten
Lance Hoffmeyer wrote: > I have the following table and I am trying to match percentage the 2nd > column on the 2nd Tiger line (9.0). > > I have tried both of the following. I expected both to match but neither > did? Is there a modifier > I am missing? What changes do I need to make these mat

Re: Regex help needed

2006-01-10 Thread Michael Spencer
rh0dium wrote: > Michael Spencer wrote: >> >>> def parse(source): >> ... source = source.splitlines() >> ... original, rest = source[0], "\n".join(source[1:]) >> ... return original, rest_eval(get_tokens(rest)) > > This is a very clean and elegant way to separate them - Very ni

Re: Regex help needed

2006-01-10 Thread Paul McGuire
"rh0dium" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Paul McGuire wrote: > > > ident = Combine( Word(alpha,alphanums+"_") + LPAR + RPAR ) > > This will only work for a word with a parentheses ( ie. somefunction() > ) > > > If you *really* want everything on the first line to b

Re: Regex help needed

2006-01-10 Thread rh0dium
Michael Spencer wrote: > >>> def parse(source): > ... source = source.splitlines() > ... original, rest = source[0], "\n".join(source[1:]) > ... return original, rest_eval(get_tokens(rest)) This is a very clean and elegant way to separate them - Very nice!! I like this alot -

Re: Regex help needed

2006-01-10 Thread rh0dium
Paul McGuire wrote: > ident = Combine( Word(alpha,alphanums+"_") + LPAR + RPAR ) This will only work for a word with a parentheses ( ie. somefunction() ) > If you *really* want everything on the first line to be the ident, try this: > > ident = Word(alpha,alphanums+"_") + restOfLine > or > ide

Re: Regex help needed

2006-01-10 Thread Michael Spencer
rh0dium wrote: > Hi all, > > I am using python to drive another tool using pexpect. The values > which I get back I would like to automatically put into a list if there > is more than one return value. They provide me a way to see that the > data is in set by parenthesising it. > ... > > CAN S

Re: Regex help needed

2006-01-10 Thread Paul McGuire
"rh0dium" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Paul McGuire wrote: > > -- Paul > > (Download pyparsing at http://pyparsing.sourceforge.net.) > > Done. > > > Hey this is pretty cool! I have one small problem that I don't know > how to resolve. I want the entire contents

Re: Regex help needed

2006-01-10 Thread rh0dium
Paul McGuire wrote: > -- Paul > (Download pyparsing at http://pyparsing.sourceforge.net.) Done. Hey this is pretty cool! I have one small problem that I don't know how to resolve. I want the entire contents (whatever it is) of line 1 to be the ident. Now digging into the code showed a method

Re: Regex help needed

2006-01-10 Thread Paul McGuire
"rh0dium" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi all, > > I am using python to drive another tool using pexpect. The values > which I get back I would like to automatically put into a list if there > is more than one return value. They provide me a way to see that the > d

Re: regex help

2005-08-11 Thread Shantanoo Mahajan
John Machin wrote: > jeff sacksteder wrote: >> Regex questions seem to be rather resistant to googling. >> >> My regex currently looks like - 'FOO:.*\n\n' >> >> The chunk of text I am attempting to locate is a line beginning with >> "FOO:", followed by an unknown number of lines, terminating wit

Re: regex help

2005-08-11 Thread gene tani
when *I* google http://www.awaretek.com/tutorials.html#regular http://en.wikibooks.org/wiki/Programming:Python_Strings http://www.regexlib.com/Default.aspx http://docs.python.org/lib/module-re.html http://diveintopython.org/regular_expressions/index.html#re.intro http://www.amk.ca/python/howto/r

Re: regex help

2005-08-11 Thread John Machin
jeff sacksteder wrote: > Regex questions seem to be rather resistant to googling. > > My regex currently looks like - 'FOO:.*\n\n' > > The chunk of text I am attempting to locate is a line beginning with > "FOO:", followed by an unknown number of lines, terminating with a > blank line. Clearly th

Re: regex help

2005-08-10 Thread Christopher Subich
jeff sacksteder wrote: > Regex questions seem to be rather resistant to googling. > > My regex currently looks like - 'FOO:.*\n\n' > > The chunk of text I am attempting to locate is a line beginning with > "FOO:", followed by an unknown number of lines, terminating with a > blank line. Clearly th