
Obviously there can't be a regex to exclude everything that isn't a regex. Parentheses can nest to unlimited depths, so you need a formal grammar. But virtually everything that is a Windows path is also formally grammatical regex too (as are many things with no plausible likely intention as such) On Oct 26, 2015 2:44 PM, "Ben Finney" <ben+python@benfinney.id.au> wrote:
Andrew Barnert via Python-ideas <python-ideas@python.org> writes:
Just for fun: is there a Python regex that matches all valid Python regexes?
Yes: ‘.*’ matches all valid Python regexes.
Obviously there's no actual regular expression that matches all regular expressions (you can't handle matched brackets without recursion or some other extension).
You seem to be seeking something else: a pattern that matches all valid regex patterns, *and* will never match any string that is not a valid regex pattern. The latter is rather more difficult.
-- \ “When I was born I was so surprised I couldn't talk for a year | `\ and a half.” —Gracie Allen | _o__) | Ben Finney
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/