Reputation: 1161
Lets say the string
str1 = "4.1% Cash Back "
str2 = "$44.2 miles "
I want to extract both "4.1%" and "$44.2" from the string. what is the best solution. I tried several methods but didn't go well.
I tried following regex:
pattern1 = r'(\d+\.\d+*%)'
pattern2 = r'$(\d+\.\d+*)'
Upvotes: 0
Views: 51
Reputation: 174
no need to escape the '.' sign and You should escape $ sign. Use Patterns as:
pattern1 = r'\d+.\d+%'
pattern2 = r'\$\d+.\d+'
Upvotes: 0