[Python-ideas] Add regex pattern literal p""
Anders Hovmöller
boxed at killingar.net
Thu Dec 27 09:01:02 EST 2018
> We can use this literal to represent a compiled pattern, for example:
>
> >>> p"(?i)[a-z]".findall("a1B2c3")
> ['a', 'B', 'c']
There are some other advantages to this. For me the most interesting is that we can know from code easier that something is a regex. For my mutation tester mutmut I have an experimental regex mutation system but it just feels wrong to write hacky heuristics to guess if a string is a regex. And it's complicated to look at too much context (although I'm working on ways to make that type of thing radically nicer to do). It would be much nicer if I could just know based on the AST node type. I guess the same goes for static analyzers.
/ Anders
More information about the Python-ideas
mailing list