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 extract variables

I try to extract 3 variables from a string with Python3 regex.

The String:

document.getElementById('dlbutton').href = "/d/05UJmMTa/" + (213059 % 51245 + 213059 % 913) + "/Cool%20Customer%20-%20In%20Your%20Face%20%28Original%20Mix%29.mp3";

I would like extract:

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

  • /d/05UJmMTa/
  • 213059 % 51245 + 213059 % 913
  • /Cool%20Customer%20-%20In%20Your%20Face%20%28Original%20Mix%29.mp3

>Solution :

Using re.findall we can try:

inp = "document.getElementById('dlbutton').href = \"/d/05UJmMTa/\" + (213059 % 51245 + 213059 % 913) + \"/Cool%20Customer%20-%20In%20Your%20Face%20%28Original%20Mix%29.mp3\";"
parts = re.findall(r'\.href\s*=\s*"(.*?)"\s*\+\s*\((.*?)\)\s*\+\s*"(.*?)"', inp)
print(parts[0])

This prints:

['/d/05UJmMTa/',
 '213059 % 51245 + 213059 % 913',
 '/Cool%20Customer%20-%20In%20Your%20Face%20%28Original%20Mix%29.mp3']
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