Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
re
#1
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
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#2
(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'
Reply
#3
(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.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020