Регулярные выражения иногда могут быть просто монструозными. Выглядеть это может крайне запутанно. Сами регэкспы и без того история непростая, а когда это длинный паттерн на несколько десятков знаков, разобрать там что-либо становится не просто.
Но на помощь приходит Python и его стремление сделать нашу жизнь проще!
В функциях регулярок можно после паттерна указывать флаги, один из которых позволяет писать паттерны более свободно. А именно, добавлять пробелы и переносы, которые будут игнорированы. В результате мы можем разбить паттерн на строки и добавить комментов.
Чтобы это сработало нужно добавить флаг re.VERBOSE. Пробелы в паттерне теперь следует указывать явно спец символами.
Согласитесь, что даже с именованными группами а таком виде регэкспа выглядит вполне сносно 😉.
#tricks#regex
🪐 Far in the constellation Carina, the peculiar galaxy ESO 137-001 speeds through the hot plasma of the Norma Cluster, leaving behind dramatic blue tendrils of stripped gas that trail for over 260,000 light-years. These glowing streams act as cosmic birthplaces, where stars are forming outside the galaxy itself—an ethereal wake marking where galactic material is torn away and reborn as new suns adrift in intergalactic space. ✨
#galaxies⚡#starformation⚡#Carina⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The star RX J0806.3–4123, located about 1,200 light-years away in the constellation Carina, is an unusual "isolated neutron star" that emits almost only X-rays and spins once every 11 seconds. Unlike most neutron stars, which are powerful radio or gamma-ray sources, RX J0806.3–4123 glows quietly and steadily, making it a rare and mysterious member of the "Magnificent Seven," a group of neutron stars that reveal the hidden diversity of how dead stars can shine. ✨
#neutronstars⚡#carina⚡#xray⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The Bullet Cluster, found in the constellation Carina, provides some of the clearest real-world evidence for dark matter—a mysterious, invisible substance making up most of the universe’s mass. When two galaxy clusters crashed together, X-ray images showed that most of the visible matter stayed at the center, but gravity maps revealed most of the mass had moved ahead, proving something unseen—dark matter—was driving the collision's aftermath. ✨
#darkmatter⚡#galaxyclusters⚡#carina⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries