Regex is fine if it works for you. The critiques – “difficult to read” –are subjective. Unless the code is in a section that has been profiled to be a bottleneck, I don’t sweat performance at this level.
For me, using code that has already been written and vetted is the preferred approach to writing new code I have to test and maintain. I use an online regex tester, https://pythex.org, to get the syntax write before copying pasting it into my code. From: Python-list <python-list-bounces+gweatherby=uchc....@python.org> on behalf of Jen Kris via Python-list <python-list@python.org> Date: Tuesday, February 28, 2023 at 1:11 PM To: Thomas Passin <li...@tompassin.net> Cc: python-list@python.org <python-list@python.org> Subject: Re: How to escape strings for re.finditer? *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Using str.startswith is a cool idea in this case. But is it better than regex for performance or reliability? Regex syntax is not a model of simplicity, but in my simple case it's not too difficult. -- https://mail.python.org/mailman/listinfo/python-list