Небольшой трик с регулярными выражениями который редко вижу в чужом коде.
Допустим, вам нужно распарсить простой текст и вытащить оттуда пары имя+телефон. Вернуть всё это надо в виде списка словарей. Возьмем очень простой пример текста.
>>> text = '''
>>> Alex:8999123456
>>> Mike:+799987654
>>> Oleg:+344456789
>>> '''
Соответственно, для выделения нужных элементов будем использовать группы. Получится такой паттерн:
(\w+):([\d+]+)
Как мы будем формировать словарь из найденных групп?
>>> import re
>>> results = []
>>> for match in re.finditer(r"(\w+):([\d+]+)", text):
>>> results.append({
>>> "name": match.group(1),
>>> "phone": match.group(2)
>>> })
>>> print(results)
[{'name': 'Alex', 'phone': '8999123456'}, ...]
Можно немного сократить запись используя zip
>>> results = []
>>> for match in re.finditer(r"(\w+):([\d+]+)", text):
>>> results.append(dict(zip(['name', 'phone'], match.groups())))
Но есть способ лучше! Это именованные группы в regex. Можно в паттерне указать имя группы и результат сразу забрать в виде словаря.
>>> for match in re.finditer(r"(?P<name>\w+):(?P<phone>[\d+]+)", text):
>>> results.append(match.groupdict())
То есть всё что я сделал, это добавил в начале группы (внутри сбокочек) такую запись:
(?P<group-name>...)
Теперь найденная группа имеет имя и можно обратиться к ней как к элементу списка
>>> name = match['name']
Либо забрать сразу весь словарь методом groupdict()
>>> match.groupdict()
#tricks#regex
Evolution X - Official | Android 16 | Nothing Phone (2)
📝 Details:
- Version: v11.4.2
- Device: #Pong
- Released: 08/01/26
⬇️ Download: ROM
📖 Changelogs: Here
🆘 Support: Discord | Telegram
🏷 Tags: #AOSP#ROM#EvoX#Official
✍️Notes:
- Use latest NOS 3 firmware! Not 4.0
- Use OrangeFox recovery to install if sideloading!
- Gapps is included, do not flash again
- Dolby is included
🏆Credits:
- Ghost and Chandu for DT
- Fabian & Ghost & HELLBOY for Glyph
- HELLBOY for Meteoric Kernel
👤 Maintainer: @Superuser1958
💬 Chat: @NothingPhone2
🔔 Updates: @NothingPhone2Updates
Evolution X - Official | Android 16 | Nothing Phone (2)
📝 Details:
- Version: v11.2
- Device: #Pong
- Released: 23/09/25
⬇️ Downloads: ROM | Recovery Image
⚙️ Flashing Instructions: Here
📖 Changelogs: Here
🆘 Support: Here
🏷 Tags: #AOSP#ROM#EvoX#Official
✍️Notes:
- Gapps is included, do not flash again
- Use latest NOS 3 firmware
- Dolby is included
🏆Credits:
- Ghost and Chandu for DT
- Fabian & HELLBOY for Glyph
- HELLBOY for Meteoric Kernel
👤 Maintainer: @Superuser1958
💬 Chat: @NothingPhone2
🔔 Updates: @NothingPhone2Updates
Evolution X - Official | Android 15 | Nothing Phone (2)
📝 Details:
- Version: v10.7
- Device: #Pong
- Released: 09/06/25
⬇️ Downloads: ROM | Recovery Image
⚙️ Flashing Instructions: Here
📖 Changelog: Here
🆘 Support: Here
🏷 Tags: #AOSP#ROM#QPR2#EvoX#Official
✍️Notes:
- Gapps is included, do not flash again!
- Use latest NOS 3 firmware
- Dolby is included
- Clean Flash is required from 10.3 or lower
🏆Credits:
- Chandu for base DT
- Ghost for Dolby and additional fixes
- Fabian & HELLBOY for Glyph
- HELLBOY for Meteoric Kernel
👤 Maintainer: @Superuser1958
🐙 Chat: @NothingPhone2
🔔 Updates: @NothingPhone2Updates
Evolution X - Official | Android 15 | Nothing Phone (2)
📝 Details:
- Version: v10.6
- Device: #Pong
- Released: 14/05/25
⬇️ Downloads: ROM | Recovery Image
⚙️ Flashing Instructions: Here
📖 Changelogs: Here
🆘 Support: Here
🏷 Tags: #AOSP#ROM#QPR2#EvoX#Official
✍️Notes:
- Gapps is included, do not flash again!
- Use latest NOS 3 firmware
- Dolby is included
- Clean Flash is required for this update
🏆Credits:
- Chandu for base DT
- Ghost for Dolby and additional fixes
- Fabian & HELLBOY for Glyph
- HELLBOY for Meteoric Kernel
👤 Maintainer: @Superuser1958
🐙 Chat: @NothingPhone2
🔔 Updates: @NothingPhone2Updates
Evolution X - Official | Android 16 | Nothing Phone (2)
📝 Details:
- Version: v11.5.2
- Device: #Pong
- Released: 03/02/26
⬇️ Download: Gapps | Vanilla
🛟 Recovery: Here
📖 Changelogs: Here
🆘 Support: Discord | Telegram
🏷 Tags: #AOSP#ROM#EvoX#Official#QPR1
✍️Notes:
- Firmware is included! (NOS 4.0)
- Sideloading/USB in recovery works as intended now
- Gapps is included, do not flash again
- Dolby is included
🏆Credits:
- Ghost and Chandu for DT
- Fabian & Ghost & HELLBOY for Glyph
- HELLBOY for Kernel base
👤 Maintainer: @Superuser1958
💬 Chat: @NothingPhone2
🔔 Updates: @NothingPhone2Updates
Evolution X - Official | Android 15 | Nothing Phone (2)
📝 Details:
- Version: v10.3
- Device: #Pong
- Released: 22/02/25
⬇️ Downloads: ROM | Recovery Image
⚙️ Flashing Instructions: Here
📖 Changelogs: Here
🆘 Support: Here
🏷 Tags: #AOSP#ROM#QPR1#EvoX#Official
✍️Notes:
- Gapps is included, do not flash again!
- Firmware is included
- Dolby is included
🏆Credits:
- Chandu for base DT
- Ghost for Dolby and additional fixes
- Fabian & HELLBOY for Glyph
- HELLBOY for Meteoric Kernel
👤 Maintainer: @Superuser1958
🐙 Chat @NothingPhone2
🔔 Updates @NothingPhone2Updates