On Sat, Aug 13, 2022 at 10:23 AM Tushar Sadhwani <tushar.sadhwani000@gmail.com> wrote:
Stephen J. Turnbull wrote:
> I think this is a pretty unconvincing example.  While people seem to
> love to hate on regular expressions, it's hard to see how that beats
> def unquote(string: str) -> str:
>         m = re.match(r"^(?:"(.*)"|'(.*)'|(?Pvalue3))$", string)

RegEx feels overkill for this. Certainly takes longer to read, understand and test.

f-strings are inherently ambiguous. You've chosen cases with unambiguous and mutually exclusive prefixes, but that won't generally be the case. You'd need implicit rules about greediness, which could easily lead to some buggy code looking correct.

For what it's worth, Raymond Hettinger has some code examples that make using regexes in match statements much easier:  see https://www.dropbox.com/s/w1bs8ckekki9ype/PyITPatternMatchingTalk.pdf?dl=0 and https://twitter.com/i/web/status/1533369943764488192

Best wishes,
Lucas Wiman