-3

How do i get values which has M at the end using Regex.

For example

some_str = '/dev/root 298.0M 210.9M 67.3M 76% /'

From above string i want to exact 298.0M , 210.9M and 67.M using Python Regex.

Sam
  • 9
  • 2

1 Answers1

-1
import re
pat = '([0-9]+.[0-9]+[M])'
re.findall(pat, "/dev/root 298.0M 210.9M 67.3M 76% /")

Output:

['298.0M', '210.9M', '67.3M']
bigbounty
  • 13,123
  • 4
  • 20
  • 50