Регулярные выражения иногда могут быть просто монструозными. Выглядеть это может крайне запутанно. Сами регэкспы и без того история непростая, а когда это длинный паттерн на несколько десятков знаков, разобрать там что-либо становится не просто.
Но на помощь приходит Python и его стремление сделать нашу жизнь проще!
В функциях регулярок можно после паттерна указывать флаги, один из которых позволяет писать паттерны более свободно. А именно, добавлять пробелы и переносы, которые будут игнорированы. В результате мы можем разбить паттерн на строки и добавить комментов.
Чтобы это сработало нужно добавить флаг re.VERBOSE. Пробелы в паттерне теперь следует указывать явно спец символами.
Согласитесь, что даже с именованными группами а таком виде регэкспа выглядит вполне сносно 😉.
#tricks#regex
G20's #DigitalInnovationAlliance is promoting #Startups with digital solutions from across the world!
Want to contribute in this global journey?
Design a logo for G20-DIA
Visit: https://www.mygov.in/task/logo-design-competition-g20-dia/
"G20-DIA bringing Hon'ble PM Narendra Modi's dream to life"
Be part of G20 #DigitalInnovationAlliance.
Know more & Apply at: meitystartuphub.in/g20-dia/
#G20India#G20DEWG
Are you interested in creating digital innovations for the upliftment of societies?
Participate in G20 #DigitalInnovationAlliance
Visit: https://mygov.in/task/launch-applications-g20-digital-innovation-alliance/
#G20DIA#G20India
Calling startups in the field of #agritech & other sectors, developing digital solutions that can reduce the digital divide and boost the global economy for G20 #DigitalInnovationAlliance.
Know more at https://mygov.in/task/launch-applications-g20-digital-innovation-alliance/
#G20India