Регулярные выражения иногда могут быть просто монструозными. Выглядеть это может крайне запутанно. Сами регэкспы и без того история непростая, а когда это длинный паттерн на несколько десятков знаков, разобрать там что-либо становится не просто.
Но на помощь приходит Python и его стремление сделать нашу жизнь проще!
В функциях регулярок можно после паттерна указывать флаги, один из которых позволяет писать паттерны более свободно. А именно, добавлять пробелы и переносы, которые будут игнорированы. В результате мы можем разбить паттерн на строки и добавить комментов.
Чтобы это сработало нужно добавить флаг re.VERBOSE. Пробелы в паттерне теперь следует указывать явно спец символами.
Согласитесь, что даже с именованными группами а таком виде регэкспа выглядит вполне сносно 😉.
#tricks#regex
After fighting for more than two months in the war and enduring another two and a half months of ceasefire, Hezbollah fighter Mohamad, who had been pronounced dead, has been found alive under the rubble in the occupied southern Lebanese village of Kfarkila along with another fighter eho was also found alive.
#Lebanon#Hezbollah#Kfarkila
Israel has begun constructing a concrete wall along the Blue Line, which separates Israel from Lebanon, encroaching on Lebanese territory.
The wall is being built inside the town of Kfar Kila, with a significant portion of the village’s land now falling within the occupied territories.
As part of the construction, the old wall was demolished, bringing the new structure even closer to the village.
This development has resulted in buildings and shops within Kfar Kila now being trapped on the wrong side of the Blue Line.
#IsraelWall#Lebanon#KfarKila#LandGrab#LebanonVsIsrael#LebaneseBorder#IsraeliAggression#BlueLine#Occupation#Israel