Regex match string containing digits and ends with x

Viewed 34

I had just recently started using regex in python, so sorry if it's too trivial. I'm trying to extract string that consists of digits and ends with letter x. For example from input asdx12x4 I want to get 12x.

I tried

import re
text = "asdx12x4"
result = re.findall("\d+x$", text)
print (result)

However result is such:

[]

Any ideas?

1 Answers
import re
text = "asdx12x4"
result = re.findall(r'\d+x', text)
print(result)

This should work - just have to change the regex

Related