Python Forum

Full Version: re
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
(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'
(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.