Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex match string containing digits and ends with x

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[]

Any ideas?

>Solution :

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

This should work – just have to change the regex

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading