Функция sub в regex может принимать функцию в качестве аргумента repl.
📄 Из документации:
If repl is a function, it is called for every non-overlapping occurrence of pattern. The function takes a single match object argument, and returns the replacement string.
То есть для каждого совпадения будет вызвана функция для вычисления замены вместо замены на одну и ту же строку для всех совпадений.
Иными словами, для замены разных совпадений на разные строки не потребуется запускать re.sub() много раз для каждой строки замены. Достаточно определить функцию, которая вернёт строку для каждого из совпадений.
Описание слишком запутанное🤔, давайте лучше рассмотрим на простом примере:
Создаем карту замены. То есть какие строки на какие требуется менять.
remap = {
'раз': '1',
'два': '2',
'три': '3',
'четыре': '4',
'пять': '5',
}
Пишем функцию поиска строки для замены. Единственным аргументом будет объект re.Match.
Используя данные этого объекта мы вычисляем замену on-the-fly!
def get_str(match: re.Match):
word = match.group(1)
return remap.get(word.lower()) or word
Пример текста.
text = '''Раз Два Три Четыре Пять
Вместе будем мы считать
Пять Четыре Три Два Раз
Мы считать научим вас
'''
Теперь запускаем re.sub и вместо строки замены (repl) подаём имя функции.
(Данный паттерн ищет отдельные слова в тексте)
>>> print(re.sub(r'(\w+)', get_str, text))
1 2 3 4 5
Вместе будем мы считать
5 4 3 2 1
Мы считать научим вас
Думаю, достаточно наглядно 🤓
#libs#regex
On the behalf of the family from Apelete. We want to thank you, thank you for the donations that made the travel, flowers and card possible. We want to thank you, thank you for the last steps you all took with Apelete on his last journey towards his piece.
Even though Apelete is not among us anymore, Apelete and his family are providing one last gift to the community because it was so dear to him, that gift will be the phones of Apelete. We will receive the phones in a few months, Onelots and TechPanelGM will take care of the legacy and make sure the legacy will be honored.
Take care of your loved ones, be grateful for the time we have and as always #KeepEvolving
We TOTALLY forgot to make an anniversary post!
Evolution X was founded on March 3, 2019, and what started as a small project has grown into a large community of users, contributors, and maintainers.
The ROM is developed and maintained in our free time, and keeping everything running also involves server and infrastructure costs.
If you enjoy Evolution X and would like to support the project, donations are welcome❤️
They are never required — your support, feedback, and simply being part of the community already mean a lot to us.
We hope you stay with us in our never-ending quest to provide the best Android experience for you.
#KeepEvolving
Hi everyone,
This isn't our standard sort of announcement, but something we need to address.
We've had to let go of a member of the team due to some information coming to light regarding their actions/messages.
I just want to take this time to make sure everyone knows that any member of the team is available to message directly with anything you need to discuss. Please tag whoever you message in one of the channels here to let us know you've messaged so we don't miss your message, or let me know you need a chat and we can message you.
While some of you may be able to put 2 and 2 together, we'd appreciate it if you please didn't discuss things publicly for the wellbeing of those who may have been affected.
As always, much love to all, and for now #KeepEvolving
November 2025 security patches have been merged into our Android 15 (now 10.11) branch. We'll do the same for our Android 14 branch soon.
While you're here, we're already starting work on our Android 16 QPR1 testing, by doing a barebones but still slightly LineageOS-based version of Evo X. What this means is there won't be any features but you will see some semblances of LineageOS during this phase. This branch of Evo X is not recommended for builders as of the moment.
This is more or less just to see what QPR1 has to offer by default. Stay tuned and #KeepEvolving
An advanced Merry Christmas and Happy new year to all 🎄☺️
We're happy to be celebrating this holiday season with everyone and we hope even a few of our Evo fam can support the team 🙏🏻
We hope to support more devices for the next security patches and we'll definitely bring a more stable experience.
#KeepEvolving
With the expected arrival of Android 14 stable source codes within the following weeks, we would like to remind users that major Android updates will definitely require several changes and might take some time in order to bring back the features included in Android 13. Initial builds will surely include less features than the current feature set available.
Android 14 will be version 8.0 for Evolution X and we will still continue the tradition of naming our versions from popular Filipino cuisine.
Android 14 will also most likely require a clean flash in order to work properly so prepare your backups now. A suggested backup app would be Swift backup from the Play store.
Thank you for continuing to support Evolution X and if you would like to help motivate a faster productivity once Android 14 sources codes are released, you may consider donating as well (crypto accepted).
We hope to provide the best and most stable builds of Evolution X once Android 14 arrives and as always, we will #KeepEvolving.
We are very excited to announce that Evolution X will be officially supporting the Google Pixel Tablet (tangorpro)! Expect initial releases to roll out within the next hour or so.
@EvolutionXPixelTablet
https://forum.xda-developers.com/t/rom-13-0_r74-official-evolution-x-7-9-7-08-23-2023.4619801/
#KeepEvolving
Wishing you a happy Lunar New Year, and may all your wishes come true! May you achieve great success in the new year and share your joy with everyone around you. Wishing you happiness, good health, and even greater success in the coming year!
Thank you again for your continuous support, let's #KeepEvolving!
Apparently, we missed our ROM's Anniversary! (March 3)
We've now been here for 3 YEARS!
Thank you to everyone who builds up and supports our huge community!
We appreciate every single user/maintainer/designer/developer who assisted and has stayed with us throughout the whole journey! To more years to come for Evolution X!
#KeepEvolving
Our website may not be available for some group of people, please do not worry, this is an issue with Cloudflare and is being worked on. Thank you
Update:
The issue is resolved, thank you for your patience and #KeepEvolving.
- Akito
In celebration of our 5.4 update, @kerichuu has decided to grace us with this wonderful creation!
Don't forget to drop by and let him know how awesome his work is! #KeepEvolving