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_
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
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
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
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
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
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
> >>> 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
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:
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?
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',
'.',
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:
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:
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',
'.',
# 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
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
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
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
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
> 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
> >-
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
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
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
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
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
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
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
>
> ...
>
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
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
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?
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
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
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
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
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
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
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 <[
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.
>>> 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
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
Thats 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
> 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
>
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
"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
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
> 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
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
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
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
"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
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 -
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
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
"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
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
"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
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
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
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
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
60 matches
Mail list logo