Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: ram@zedat.fu-berlin.de (Stefan Ram) Newsgroups: comp.lang.python,alt.fantasy Subject: Re: Pythonic way to combine regular expressions? Followup-To: comp.lang.python Date: 26 Sep 2026 12:22:14 GMT Organization: Stefan Ram Lines: 33 Expires: 1 Sep 2027 11:59:58 GMT Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de QZxXtxTqmt2p4f89gGv29AIAfVgsdD+XCRXLBQ4TwxNVBS Cancel-Lock: sha1:WkCeQGO0kDfTnYQTKK6+FU1pmXs= sha256:N5jY9lsbHqWVIoq6F6VOr3tuQfww2mHqs1xgke2g03U= X-Copyright: (C) Copyright 2026 Stefan Ram. All rights reserved. Distribution through any means other than regular usenet channels is forbidden. It is forbidden to publish this article in the Web, to change URIs of this article into links, and to transfer the body without this notice, but quotations of parts in other Usenet posts are allowed. X-No-Archive: Yes Archive: no X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some services to mirror the article in the web. But the article may be kept on a Usenet archive server with only NNTP access. X-No-Html: yes Content-Language: en Xref: csiph.com comp.lang.python:198080 alt.fantasy:686 Johann 'Myrkraverk' Oskarsson wrote or quoted: >Thank you. I'm sure Kent Beck of /eXtreme Programming/ would be proud >of this regular expression if he bothered to read comp.lang.python. That regular expression can be made more readable in Python using verbose regular expressions while still avoiding names and parentheses within the regular expression. exp = re.compile( r""" ^ [+-]? [0-9]+ $ # Integer (123, -45) | ^ [+-]? [0-9]+ \. [0-9]+ [eE] [+-]? [0-9]+ $ # Float with "E" | ^ [+-]? [0-9]+ \. [0-9]+ $ # Float without "E" | ^ [+-]? \. [0-9]+ [eE] [+-]? [0-9]+ $ # Starts with ".", has E | ^ [+-]? \. [0-9]+ $ # Starts with ".", no "E" | ^ [+-]? [0-9]+ \. [eE] [+-]? [0-9]+ $ # Ends with ".", has "E" | ^ [+-]? [0-9]+ \. $ # Ends with ".", no "E" | ^ [+-]? [0-9]+ [eE] [+-]? [0-9]+ $ # No ".", but "E" """, re.VERBOSE, ) Newsgroups: comp.lang.python,alt.fantasy Followup-To: comp.lang.python