Регулярные выражения иногда могут быть просто монструозными. Выглядеть это может крайне запутанно. Сами регэкспы и без того история непростая, а когда это длинный паттерн на несколько десятков знаков, разобрать там что-либо становится не просто.
Но на помощь приходит Python и его стремление сделать нашу жизнь проще!
В функциях регулярок можно после паттерна указывать флаги, один из которых позволяет писать паттерны более свободно. А именно, добавлять пробелы и переносы, которые будут игнорированы. В результате мы можем разбить паттерн на строки и добавить комментов.
Чтобы это сработало нужно добавить флаг re.VERBOSE. Пробелы в паттерне теперь следует указывать явно спец символами.
Согласитесь, что даже с именованными группами а таком виде регэкспа выглядит вполне сносно 😉.
#tricks#regex
🌎 In Papua New Guinea, the Korowai people still build treehouses perched up to 35 meters above ground. This tradition began as a way to avoid floods, wild animals, and rival clans. Some Korowai treehouses even have separate “guest” platforms for visitors or ritual gatherings. ✨
#anthropology⚡#traditions⚡#rituals
👉subscribe Interesting Planet
👉more Channels
🌎 In Vanuatu, the Naghol or "land diving" ritual involves men jumping from tall wooden towers with vines tied to their ankles. This dangerous tradition, practiced on Pentecost Island, is meant to ensure a good yam harvest. Some platforms are over 20 meters high, and proper vine length is crucial to prevent injury. ✨
#traditions⚡#anthropology⚡#rituals
👉subscribe Interesting Planet
👉more Channels
🌎 In Spain’s Catalonia region, families celebrate Christmas with the “Caga Tió,” or “pooping log.” Children decorate a wooden log with a face, cover it with a blanket, and “feed” it every night. On Christmas Eve, they beat the log with sticks while singing a traditional song, and small gifts and sweets are found underneath the blanket. The custom dates back at least to the 18th century. ✨
#traditions⚡#rituals⚡#culture
👉subscribe Interesting Planet
👉more Channels
🌎 In the Indonesian village of Trunyan, the dead are laid out on the ground and covered with bamboo cages instead of being buried. The local Taru Menyan tree releases a natural fragrance that masks odors, allowing bodies to decompose above ground without attracting scavengers. ✨
#rituals⚡#anthropology⚡#Indonesia
👉subscribe Interesting Planet
👉more Channels