Регулярные выражения иногда могут быть просто монструозными. Выглядеть это может крайне запутанно. Сами регэкспы и без того история непростая, а когда это длинный паттерн на несколько десятков знаков, разобрать там что-либо становится не просто.
Но на помощь приходит Python и его стремление сделать нашу жизнь проще!
В функциях регулярок можно после паттерна указывать флаги, один из которых позволяет писать паттерны более свободно. А именно, добавлять пробелы и переносы, которые будут игнорированы. В результате мы можем разбить паттерн на строки и добавить комментов.
Чтобы это сработало нужно добавить флаг re.VERBOSE. Пробелы в паттерне теперь следует указывать явно спец символами.
Согласитесь, что даже с именованными группами а таком виде регэкспа выглядит вполне сносно 😉.
#tricks#regex
🌍 In Chile's Atacama Desert, rare fog called "camanchaca" drifts inland from the Pacific. Some plants here survive by absorbing water directly from this fog, not from rainfall. ✨
#desert⚡#arid⚡#adaptation⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Some arid desert landscapes feature ancient, dried-up riverbeds called wadis that can flood suddenly after rare rains, quickly turning from bare channels to rushing streams in a matter of hours. ✨
#desert⚡#arid⚡#landscapes⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Libya’s Libyan Desert holds sand seas with dunes reaching up to 180 meters tall. These giant dunes constantly shift with the wind, creating landscapes that can look completely different in just a few years. ✨
#desert⚡#dunes⚡#arid⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In the Taklamakan Desert of China, some sand dunes reach up to 300 meters tall. Shifting winds keep these giant dunes moving, constantly reshaping the landscape year after year. ✨
#deserts⚡#dunes⚡#arid⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 The Atacama Desert in Chile is so dry that some weather stations have never recorded rain. Its Mars-like soils are studied by scientists searching for signs of life in extreme environments. ✨
#desert⚡#extreme⚡#arid⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 The Namib Desert is thought to be the oldest desert on Earth, with arid conditions lasting for at least 55 million years—far longer than any other known desert. ✨
#desert⚡#Namib⚡#arid⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍