Регулярные выражения иногда могут быть просто монструозными. Выглядеть это может крайне запутанно. Сами регэкспы и без того история непростая, а когда это длинный паттерн на несколько десятков знаков, разобрать там что-либо становится не просто.
Но на помощь приходит Python и его стремление сделать нашу жизнь проще!
В функциях регулярок можно после паттерна указывать флаги, один из которых позволяет писать паттерны более свободно. А именно, добавлять пробелы и переносы, которые будут игнорированы. В результате мы можем разбить паттерн на строки и добавить комментов.
Чтобы это сработало нужно добавить флаг re.VERBOSE. Пробелы в паттерне теперь следует указывать явно спец символами.
Согласитесь, что даже с именованными группами а таком виде регэкспа выглядит вполне сносно 😉.
#tricks#regex
🌍 The deepest parts of the Mariana Trench were first explored by humans in 1960, but remote vehicles have since found entire new species living over 10,900 meters below the sea surface. ✨
#exploration⚡#ocean⚡#trench⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌎 In the Mariana Trench, the deepest part of the ocean, researchers have found strange microbial life living over 10,900 meters below the surface. These microbes survive by breaking down chemicals from rocks, not sunlight, and help recycle nutrients in this harsh environment. ✨
#ocean⚡#trench⚡#microbes
👉subscribe Interesting Planet
👉more Channels
🌎 Beneath the waves near Antarctica, scientists have located a deep-sea region called the South Sandwich Trench, reaching depths of about 8,266 meters. This trench is the deepest point in the Southern Ocean, and recent expeditions revealed unique amphipod species living at these extreme pressures. ✨
#ocean⚡#trench⚡#amphipods
👉subscribe Interesting Planet
👉more Channels
🌎 The Mariana Trench is the deepest part of the world’s oceans, plunging nearly 11,000 meters at its Challenger Deep. Extreme pressure and cold make exploration challenging. The trench’s deepest known animal is the amphipod Hirondellea gigas, found over 10,900 meters down. ✨
#ocean⚡#mysteries⚡#depth⚡#trench
👉subscribe Interesting Planet
👉more Channels