Avatar ·

Using a variable in a Python regular expression

📁 Advanced Python Topics, AI

Hello! Please help me solve what seems like a trivial task, but due to lack of programming experience, it's absolutely impossible for me :)

mt=re.findall(r'\\'""variable""\\s\\'')

Instead of ""variable"" there should be a variable into which different strings will be substituted, but I don't know how to present it correctly.

Avatar ·

So, I'll add to the piggy bank:

import rea = ""ThisIsCamelCaseExample""b=list(a)[b.insert(x,'_') for x in [m.start() for m in re.finditer(""[A-Z]"",a)][:0:-1]]res = ''.join(b).lower()print(res)

this_is_camel_case_example

Log in to leave an answer

Blogs