removing text string

Ahmed, Shakir shahmed at sfwmd.gov
Thu Sep 11 09:40:21 EDT 2008



-----Original Message-----
From: python-list-bounces+shahmed=sfwmd.gov at python.org
[mailto:python-list-bounces+shahmed=sfwmd.gov at python.org] On Behalf Of
bearophileHUGS at lycos.com
Sent: Thursday, September 11, 2008 8:54 AM
To: python-list at python.org
Subject: Re: removing text string

Ahmed, Shakir:
> Actually the number I am getting it is from slicing from a long text
> line. I need to slice 10 characters from that line but no string only
> numeric numbers. When I am slicing 10 characters those A, c, O is
coming
> at the end.

It's better to avoid Regular expressions when they aren't necessary,
but once in a while they are the simpler way to solve a problem, you
may create one like this (mostly untested):

\d+?-\d+

Using it like:

>>> import re
>>> patt = re.compile(r"\d+?-\d+")
>>> patt.search("xxxxxx080829-7_A xxxx").group()
'080829-7'
>>> re.search(r"\d+?-\d+", "xxxxxx080829-7_A xxxx").group()
'080829-7'

Learning Regexps can be useful.

Bye,
Bearophile


Thanks, I got the clue.

Very much appreciated.


--
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list