Python Forum
re - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: re (/thread-34287.html)



re - menator01 - Jul-15-2021

Trying to understand regexp a little.
Taking this string 01-09- Money Honey, I'm trying to get just the Money Honey part.
the closest I've gotten is this output
Output:
['', '', '-', '', '', '- Money Honey', '']
using
patt = '(\D*)'
print(re.findall(patt, display_label))
any help is much appreciated


RE: re - snippsat - Jul-15-2021

(Jul-15-2021, 09:04 AM)menator01 Wrote: 'm trying to get just the Money Honey part.
Something like this.
>>> import re 
>>> 
>>> s = '01-09- Money Honey'
>>> re.findall(r'\w+\s\w+', s)
['Money Honey']
>>> 
>>> r = re.search(r'(\w+\s\w+)', s)
>>> r.group(1)
'Money Honey'



RE: re - menator01 - Jul-15-2021

(Jul-15-2021, 01:27 PM)snippsat Wrote:
(Jul-15-2021, 09:04 AM)menator01 Wrote: 'm trying to get just the Money Honey part.
Something like this.
>>> import re 
>>> 
>>> s = '01-09- Money Honey'
>>> re.findall(r'\w+\s\w+', s)
['Money Honey']
>>> 
>>> r = re.search(r'(\w+\s\w+)', s)
>>> r.group(1)
'Money Honey'

Many thanks, that has gave me something to play around with.