Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #198080

Re: Pythonic way to combine regular expressions?

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 2026-09-26 12:22 +0000
Organization Stefan Ram
Message-ID <VERBOSE-20260926132029@ram.dialup.fu-berlin.de> (permalink)
References <MrztS.208529$Nn1.7474@fx18.ams4> <names-20260926110359@ram.dialup.fu-berlin.de> <TBOtS.247604$4yM7.183409@fx08.ams4>

Cross-posted to 2 groups.

Followups directed to: comp.lang.python

Show all headers | View raw


Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> 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

Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Pythonic way to combine regular expressions? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-26 02:54 +0800
  Re: Pythonic way to combine regular expressions? ram@zedat.fu-berlin.de (Stefan Ram) - 2026-09-25 19:08 +0000
    Re: Pythonic way to combine regular expressions? ram@zedat.fu-berlin.de (Stefan Ram) - 2026-09-25 19:19 +0000
  Re: Pythonic way to combine regular expressions? ram@zedat.fu-berlin.de (Stefan Ram) - 2026-09-26 10:04 +0000
    Re: Pythonic way to combine regular expressions? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-26 20:09 +0800
      Re: Pythonic way to combine regular expressions? ram@zedat.fu-berlin.de (Stefan Ram) - 2026-09-26 12:22 +0000

csiph-web