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

Python Regex: Matching only if x is preceded by a digit

Im trying to make a Regex pattern that matches only if:

A "x" is after a digit, returns match for example if:

3x + 1
2x
40x
2 + 33x

Dont match if:

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

x + 2
2 + x

is it possible?

>Solution :

In Python the following regex should work

(\d+)x

I’m assuming you want to capture the number attached to "x" in these equations. I’m also making a (rather big) assumption here that the equations provided will be correct i.e. the equations are valid.

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