32
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
this post was submitted on 23 Jul 2024
32 points (100.0% liked)
Python
6325 readers
236 users here now
Welcome to the Python community on the programming.dev Lemmy instance!
📅 Events
Past
November 2023
- PyCon Ireland 2023, 11-12th
- PyData Tel Aviv 2023 14th
October 2023
- PyConES Canarias 2023, 6-8th
- DjangoCon US 2023, 16-20th (!django 💬)
July 2023
- PyDelhi Meetup, 2nd
- PyCon Israel, 4-5th
- DFW Pythoneers, 6th
- Django Girls Abraka, 6-7th
- SciPy 2023 10-16th, Austin
- IndyPy, 11th
- Leipzig Python User Group, 11th
- Austin Python, 12th
- EuroPython 2023, 17-23rd
- Austin Python: Evening of Coding, 18th
- PyHEP.dev 2023 - "Python in HEP" Developer's Workshop, 25th
August 2023
- PyLadies Dublin, 15th
- EuroSciPy 2023, 14-18th
September 2023
- PyData Amsterdam, 14-16th
- PyCon UK, 22nd - 25th
🐍 Python project:
- Python
- Documentation
- News & Blog
- Python Planet blog aggregator
💓 Python Community:
- #python IRC for general questions
- #python-dev IRC for CPython developers
- PySlackers Slack channel
- Python Discord server
- Python Weekly newsletters
- Mailing lists
- Forum
✨ Python Ecosystem:
🌌 Fediverse
Communities
- #python on Mastodon
- c/django on programming.dev
- c/pythorhead on lemmy.dbzer0.com
Projects
- Pythörhead: a Python library for interacting with Lemmy
- Plemmy: a Python package for accessing the Lemmy API
- pylemmy pylemmy enables simple access to Lemmy's API with Python
- mastodon.py, a Python wrapper for the Mastodon API
Feeds
founded 1 year ago
MODERATORS
I would argue that having distinct
match
andsearch
helps readability. The difference betweenmatch('((([0-9]+-[0-9]+)|([0-9]+))[,]?)+[^,]', s)
andsearch('((([0-9]+-[0-9]+)|([0-9]+))[,]?)+[^,]', s)
is clear without the need for me to parse the regular expression myself. It also helps code reuse. Consider that you havePHONE_NUMBER_REGEX
defined somewhere. If you only had a method to "search" but not to "match", you would have to do something likesearch(f"\A{PHONE_NUMBER_REGEX}\Z", s)
, which is error-prone and less readable. Most likely you would end up having at least two sets of precompiled regex objects (i.e.PHONE_NUMBER_REGEX
andPHONE_NUMBER_FULLMATCH_REGEX
). It is also a fairly common practice in other languages' regex libraries (cf. [1,2]). Golang, which is usually very reserved in the number of ways to express the same thing, has 16 different matching methods[3].Regarding
re.findall
, I see what you mean, however I don't agree with your conclusions. I think it is a useful convenience method that improves readability in many cases. I've found these usages from my code, and I'm quite happy that this method was available[4]:[1] https://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html
[2] https://en.cppreference.com/w/cpp/regex
[3] https://pkg.go.dev/regexp
[4] https://github.com/search?q=repo%3Ahades%2Faoc23%20findall&type=code
Thank you for the very thorough reply! This is kind of high quality stuff you love to see on Lemmy. Your use cases seem very valid.