
Sometimes when I do complicated regular expressions, I like to divide the patterns from a big pattern to small patterns until I reach what I want. re module functions take the text as a second argument. Furthermore, you can’t pass the Match object directly, you need to extract the group/text from it. If we have a placeholder for the passed argument, we could do both 1) put it wherever we want, not necessarily first 2) further manipulate it so it becomes a valid argument number = text -> re.search(pattern1, _) -> re.search(pattern2, _.group(0)) -> re.search(pattern3, _.group(1)) -> float(_.group(0)) Yeah that can look ugly I agree (here intentionally the placeholder is overused). But the person can still write a flowing chained operation if they want or if it’s easier for them to understand. Or just do it the traditional way … text1 = re.search(pattern1, text).group(0) text2 = re.search(pattern2, text1).group(1) text3 = re.search(pattern3, text2).group(0) number = float(text3)
It's always possible to make a proposal more general by making it less clean. Is the loss of generality from "must pipe into the first argument" (or "must pipe into last argument", pick whichever one you want to go with) actually as restrictive as you think? People don't tend to write add() and pow() like this, because we have operators. With real-world code, how commonly is this actually going to be a problem?
ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org <mailto:python-ideas@python.org> To unsubscribe send an email to python-ideas-leave@python.org <mailto:python-ideas-leave@python.org> https://mail.python.org/mailman3/lists/python-ideas.python.org/ <https://mail.python.org/mailman3/lists/python-ideas.python.org/> Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/YAWWKU... <https://mail.python.org/archives/list/python-ideas@python.org/message/YAWWKU...> Code of Conduct: http://python.org/psf/codeofconduct/ <http://python.org/psf/codeofconduct/>