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

regex help

2015-03-13 Thread Larry Martell
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.9423076923076925,5.7884615384615383,5.1

Re: Newbie needs regex help

2010-12-06 Thread Dan M
On Mon, 06 Dec 2010 18:12:33 +0100, Peter Otten wrote: > By the way: > print quopri.decodestring("=E4=F6=FC").decode("iso-8859-1") > äöü print r"\xe4\xf6\xfc".decode("string-escape").decode("iso-8859-1") > äöü Ah - better than a regex. Thanks! -- http://mail.python.org/mailman/listin

Re: Newbie needs regex help

2010-12-06 Thread Peter Otten
Dan M wrote: > I'm getting bogged down with backslash escaping. > > I have some text files containing characters with the 8th bit set. These > characters are encoded one of two ways: either "=hh" or "\xhh", where "h" > represents a hex digit, and "\x" is a literal backslash followed by a > lower-

Re: Newbie needs regex help

2010-12-06 Thread Dan M
On Mon, 06 Dec 2010 09:44:39 -0600, Dan M wrote: > That's what I had initially assumed was the case, but looking at the > data files with a hex editor showed me that I do indeed have > four-character sequences. That's what makes this such as interesting > task! Sorry, I misunderstood the first ti

Re: Newbie needs regex help

2010-12-06 Thread Dan M
On Mon, 06 Dec 2010 16:34:56 +0100, Alain Ketterlin wrote: > Dan M writes: > >> I took at look at http://docs.python.org/howto/regex.html, especially >> the section titled "The Backslash Plague". I started out trying : > > import re > r = re.compile('x([0-9a-fA-F]{2})') a = "This \x

Re: Newbie needs regex help

2010-12-06 Thread Dan M
On Mon, 06 Dec 2010 10:29:41 -0500, Mel wrote: > What you're missing is that string `a` doesn't actually contain four- > character sequences like '\', 'x', 'a', 'a' . It contains single > characters that you encode in string literals as '\xaa' and so on. You > might do better with > > p1 = r'([

Re: Newbie needs regex help

2010-12-06 Thread Alain Ketterlin
Dan M writes: > I took at look at http://docs.python.org/howto/regex.html, especially the > section titled "The Backslash Plague". I started out trying : import re r = re.compile('x([0-9a-fA-F]{2})') a = "This \xef file \xef has \x20 a bunch \xa0 of \xb0 crap \xc0 The backs

Re: Newbie needs regex help

2010-12-06 Thread Mel
Dan M wrote: > I'm getting bogged down with backslash escaping. > > I have some text files containing characters with the 8th bit set. These > characters are encoded one of two ways: either "=hh" or "\xhh", where "h" > represents a hex digit, and "\x" is a literal backslash followed by a > lower-

Newbie needs regex help

2010-12-06 Thread Dan M
I'm getting bogged down with backslash escaping. I have some text files containing characters with the 8th bit set. These characters are encoded one of two ways: either "=hh" or "\xhh", where "h" represents a hex digit, and "\x" is a literal backslash followed by a lower-case x. Catching the f

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', '.',

regex help: splitting string gets weird groups

2010-04-08 Thread gry
[ 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', '.', 'in', '#', '=

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

Regex help needed!

2009-12-21 Thread Oltmans
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's kind of working

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

regex help

2009-12-16 Thread Gabriel Rossetti
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 ... the node may be absent or empty (), the node may be absent. I'd like to grab everything exept the

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

regex help

2009-07-08 Thread David
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 to get to. Problem 1 - (25.47%) I want to extract 25

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: More regex help

2008-09-24 Thread Support Desk
Kirk, That's exactly what I needed. Thx! -Original Message- From: Kirk Strauser [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 24, 2008 11:42 AM To: python-list@python.org Subject: Re: More regex help At 2008-09-24T16:25:02Z, "Support Desk" <[EMAIL PROTECTED

Re: More regex help

2008-09-24 Thread Kirk Strauser
At 2008-09-24T16:25:02Z, "Support Desk" <[EMAIL PROTECTED]> writes: > I am working on a python webcrawler, that will extract all links from an > html page, and add them to a queue, The problem I am having is building > absolute links from relative links, as there are so many different types of > r

More regex help

2008-09-24 Thread Support Desk
I am working on a python webcrawler, that will extract all links from an html page, and add them to a queue, The problem I am having is building absolute links from relative links, as there are so many different types of relative links. If I just append the relative links to the current url, some w

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.

Regex Help

2008-09-22 Thread Support Desk
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 am using is regex = r'' page_text = urllib.urlopen('http://somesit

RE: regex help

2008-06-30 Thread Metal Zong
" % item ... else: ... print "%d valid" % item ... 281 invalid 713 invalid 832 invalid 1281 invalid 1713 invalid 1832 invalid 2281 valid 2713 valid 2832 valid >>> _ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Support Desk Se

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

regex help

2008-06-30 Thread Support Desk
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 does'nt start with: 281 713 832 or 1281 1713 1832

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

regex help

2008-06-03 Thread Support Desk
I am trying to put together a regular expression that will rename users address books on our server due to a recent change we made. Users with address books user.abook need to be changed to [EMAIL PROTECTED] I'm having trouble with the regex. Any help would be appreciated. -Mike -- http://mai

Re: pexpect regex help

2007-02-23 Thread amadain
On Feb 23, 8:53 am, "amadain" <[EMAIL PROTECTED]> wrote: > On Feb 23, 8:46 am, "amadain" <[EMAIL PROTECTED]> wrote: > > > > > On Feb 21, 11:15 pm, [EMAIL PROTECTED] wrote: > > > > On Feb 21, 6:13 pm, [EMAIL PROTECTED] wrote: > > > > > I have apexpectscript to walk through a cisco terminal server an

Re: pexpect regex help

2007-02-23 Thread amadain
On Feb 23, 8:46 am, "amadain" <[EMAIL PROTECTED]> wrote: > On Feb 21, 11:15 pm, [EMAIL PROTECTED] wrote: > > > > > On Feb 21, 6:13 pm, [EMAIL PROTECTED] wrote: > > > > I have apexpectscript to walk through a cisco terminal server and I > > > was hoping to get some help with this regex because I rea

Re: pexpect regex help

2007-02-23 Thread amadain
On Feb 21, 11:15 pm, [EMAIL PROTECTED] wrote: > On Feb 21, 6:13 pm, [EMAIL PROTECTED] wrote: > > > > > I have apexpectscript to walk through a cisco terminal server and I > > was hoping to get some help with this regex because I really suck at > > it. > > > This is the code: > > > index = s

Re: pexpect regex help

2007-02-21 Thread jonathan . sabo
On Feb 21, 6:13 pm, [EMAIL PROTECTED] wrote: > I have a pexpect script to walk through a cisco terminal server and I > was hoping to get some help with this regex because I really suck at > it. > > This is the code: > > index = s.expect(['login: ', pexpect.EOF, pexpect.TIMEOUT]) > i

pexpect regex help

2007-02-21 Thread jonathan . sabo
I have a pexpect script to walk through a cisco terminal server and I was hoping to get some help with this regex because I really suck at it. This is the code: index = s.expect(['login: ', pexpect.EOF, pexpect.TIMEOUT]) if index == 0: m = re.search('((#.+\r\n){20,25})

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

Regex help...pretty please?

2006-08-23 Thread MooMaster
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 themselves may have conds within, like the

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

regex help

2006-05-16 Thread Lance Hoffmeyer
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 match? I need to keep the structure

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
rovide me a way to see that the > data is in set by parenthesising it. > Well, you asked for regex help, but a pyparsing rendition may be easier to read and maintain. -- Paul (Download pyparsing at http://pyparsing.sourceforge.net.) # test data strings test1 = """somefunction(

Regex help needed

2006-01-10 Thread rh0dium
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. This is all generated as I said using pexpec

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

regex help

2005-08-10 Thread jeff sacksteder
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 the ".*" phrase does not match the sing

Re: Multiline regex help

2005-03-03 Thread Kent Johnson
Steven Bethard wrote: Kent Johnson wrote: for line in raw_data: if line.startswith('RelevantInfo1'): info1 = raw_data.next().strip() elif line.startswith('RelevantInfo2'): info2 = raw_data.next().strip() elif line.startswith('RelevantInfo3'): info3 = raw_data.nex

Re: Multiline regex help

2005-03-03 Thread Steven Bethard
Kent Johnson wrote: for line in raw_data: if line.startswith('RelevantInfo1'): info1 = raw_data.next().strip() elif line.startswith('RelevantInfo2'): info2 = raw_data.next().strip() elif line.startswith('RelevantInfo3'): info3 = raw_data.next().strip() sc

Re: Multiline regex help

2005-03-03 Thread Yatima
On Thu, 3 Mar 2005 12:26:37 -0800, James Stroud <[EMAIL PROTECTED]> wrote: > Have a look at "martel", part of biopython. The world of bioinformatics is > filled with files with structure like this. > > http://www.biopython.org/docs/api/public/Martel-module.html > > James Thanks for the link. Stev

Re: Multiline regex help

2005-03-03 Thread Yatima
On Thu, 03 Mar 2005 16:25:39 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote: > Here is another attempt. I'm still not sure I understand what form you want > the data in. I made a > dict -> dict -> list structure so if you lookup e.g. scores['10/11/04']['60'] > you get a list of all > the Relevan

Re: Multiline regex help

2005-03-03 Thread Yatima
On Thu, 03 Mar 2005 13:45:31 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: > > I think if you use the non-greedy .*? instead of the greedy .*, you'll > get this behavior. For example: > > py> s = """\ > ... Gibberish > ... 53 > ... MoreGarbage > [snip a whole bunch of stuff] > ... RelevantInfo

Re: Multiline regex help

2005-03-03 Thread Kent Johnson
Here is another attempt. I'm still not sure I understand what form you want the data in. I made a dict -> dict -> list structure so if you lookup e.g. scores['10/11/04']['60'] you get a list of all the RelevantInfo2 values for Relevant1='10/11/04' and Relevant2='60'. The parser is a simple-minde

Re: Multiline regex help

2005-03-03 Thread Steven Bethard
Yatima wrote: On Thu, 03 Mar 2005 09:54:02 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: A possible solution, using the re module: py> s = """\ ... Gibberish ... 53 ... MoreGarbage ... 12 ... RelevantInfo1 ... 10/10/04 ... NothingImportant ... ThisDoesNotMatter ... 44 ... RelevantInfo2 ... 22 ..

Re: Multiline regex help

2005-03-03 Thread James Stroud
I found the original paper for Martel: http://www.dalkescientific.com/Martel/ipc9/ On Thursday 03 March 2005 12:26 pm, James Stroud wrote: > Have a look at "martel", part of biopython. The world of bioinformatics is > filled with files with structure like this. > > http://www.biopython.org/docs/a

Re: Multiline regex help

2005-03-03 Thread Yatima
On Thu, 03 Mar 2005 07:14:50 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote: > > Here is a way to create a list of [RelevantInfo, value] pairs: > import cStringIO > > raw_data = '''Gibberish > 53 > MoreGarbage > 12 > RelevantInfo1 > 10/10/04 > NothingImportant > ThisDoesNotMatter > 44 > RelevantInfo

Re: Multiline regex help

2005-03-03 Thread James Stroud
Have a look at "martel", part of biopython. The world of bioinformatics is filled with files with structure like this. http://www.biopython.org/docs/api/public/Martel-module.html James On Thursday 03 March 2005 12:03 pm, Yatima wrote: > On Thu, 03 Mar 2005 09:54:02 -0700, Steven Bethard <[EMAI

Re: Multiline regex help

2005-03-03 Thread Yatima
On Thu, 03 Mar 2005 09:54:02 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: > > A possible solution, using the re module: > > py> s = """\ > ... Gibberish > ... 53 > ... MoreGarbage > ... 12 > ... RelevantInfo1 > ... 10/10/04 > ... NothingImportant > ... ThisDoesNotMatter > ... 44 > ... RelevantI

Re: Multiline regex help

2005-03-03 Thread Steven Bethard
Yatima wrote: Hey Folks, I've got some info in a bunch of files that kind of looks like so: Gibberish 53 MoreGarbage 12 RelevantInfo1 10/10/04 NothingImportant ThisDoesNotMatter 44 RelevantInfo2 22 BlahBlah 343 RelevantInfo3 23 Hubris Crap 34 and so on... Anyhow, these "fields" repeat several times

  1   2   >