Use variable with regular expression in python. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Use variable with regular expression in python.

How do i use a variable inside the regular expression given below. v = re.findall(r'/VARIABLE/(\d\d\d)">', html)

7th May 2017, 3:29 PM
buggythegret
buggythegret - avatar
3 Answers
+ 7
The simplest would be to build the regex pattern by concatenating what is before the string variable, the variable itself and what is after it. v = re.findall(VARIABLE+r'(\d\d\d)">', html)
7th May 2017, 3:37 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 3
concatenation!! haha. the answer was so simple yet it had worried.
7th May 2017, 4:02 PM
buggythegret
buggythegret - avatar
+ 3
Sure :) Anyway, there are lots of good libraries for HTML parsing, you could try 'beautifulsoup' for example. It makes the whole data scraping a loooot easier :)
7th May 2017, 4:16 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar