Home > Blockchain >  Regex match string containing digits and ends with x
Regex match string containing digits and ends with x

Time:03-07

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?

CodePudding user response:

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

This should work - just have to change the regex

  • Related