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 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.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 better/improved Regex. Thank you
> in advance.

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


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 need the digits within the ID attribute of
> the DIV. Regex that you suggested fails on the following string
>
> 
> lksjdfls  kdjff lsdfs  sdjfls  =   "amazon_35343433">sdfsdwelcome
> hello, my age is 86 years old and I was born in 1945. Do you know that
> PI is roughly 3.1443534534534534534
> 
>
> > ~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 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.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 better/improved Regex. Thank you
> > > in advance.
>
>

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


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 only need the digits within the ID attribute of
> the DIV. Regex that you suggested fails on the following string
>
> 
> lksjdfls  kdjff lsdfs  sdjfls  =   "amazon_35343433">sdfsdwelcome
> hello, my age is 86 years old and I was born in 1945. Do you know that
> PI is roughly 3.1443534534534534534
> 
>
> > ~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 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.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 better/improved Regex. Thank you
> > > in advance.
>
>

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