-2

I am new to python regex. I want to match the pattern 'word.word'. For example:

s = '''seven hundred people found dead devastating seven.eight magnitude earthquake hits Nepal'''

re.findall(r'^[\w]*[.]*[\w]*', s, flags=re.IGNORECASE)

It finds only the first word. Can not figure out a way to solve this. Thanks for any support.

Totura
  • 19
  • 1
  • 7

2 Answers2

0
re.findall(r'\w*\.\w*', s, flags=re.IGNORECASE)

will give you the result:

['seven.eight']
David
  • 2,926
  • 1
  • 27
  • 61
0

following code will give you the answer

s = '''seven hundred people found dead devastating seven.eight magnitude earthquake hits Nepal'''
re.findall(r'(\w*\.\w*)', s)

regex demo

your ^[\w]*[.]*[\w]* regex uses * quantifier which matches previous character from zero to unlimited. Also ^ matches from start of the string, so your regex matches until the space between first word (seven) and second word (hundred) and it doesn't need to match anything else and stops.

mjrezaee
  • 1,100
  • 5
  • 9