On 11/17/2023 9:46 AM, Peter J. Holzer via Python-list wrote:
On 2023-11-17 07:48:41 -0500, Thomas Passin via Python-list wrote:
On 11/17/2023 6:17 AM, Peter J. Holzer via Python-list wrote:
Oh, and Python (just like Perl) allows you to embed whitespace and
comments into Regexps, which helps readability a lot if you have to
write long regexps.

[...]
re.findall(r'\b[0-9]{2,7}-[0-9]{2}-[0-9]{2}\b', txt)

\b         - a word boundary.
[0-9]{2,7} - 2 to 7 digits
-          - a hyphen-minus
[0-9]{2}   - exactly 2 digits
-          - a hyphen-minus
[0-9]{2}   - exactly 2 digits
\b         - a word boundary.

Seems quite straightforward to me. I'll be impressed if you can write
that in Python in a way which is easier to read.

And the re.VERBOSE (also re.X) flag can always be used so the entire
expression can be written line-by-line with comments nearly the same
as the example above

Yes. That's what I alluded to above.

I know, and I just wanted to make it explicit for people who didn't know much about Python regexes.

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to