Re: [Python-ideas] Add regex pattern literal p""

2018-12-30 Thread Alexander Heger
> What's more, it's a tool that should be used > with considerable reluctance, because REs are essentially unreadable, > so every time you use one you're creating a maintenance headache. Well, it requires some experience to read REs, I have written many, and I still need to test thoroughly even

Re: [Python-ideas] Add regex pattern literal p""

2018-12-30 Thread Greg Ewing
I don't see a justification for baking REs into the syntax of Python. In the Python world, REs are just one tool in a toolbox containing a great many tools. What's more, it's a tool that should be used with considerable reluctance, because REs are essentially unreadable, so every time you use

Re: [Python-ideas] Add regex pattern literal p""

2018-12-30 Thread Greg Ewing
Steven D'Aprano wrote: _t1 = re.compile(r"(\d)\1") # compile-time _t2 = re.compile(r"(\s)\1") # compile-time re.compile(_t1.pattern + _t2.pattern) # run-time It would be weird if p"(\d)\1" + p"(\s)\1" worked but re.compile(r"(\d)\1") + re.compile(r"(\s)\1") didn't. -- Greg

Re: [Python-ideas] Add regex pattern literal p""

2018-12-28 Thread Nathan Schneider
On Sat, Dec 29, 2018 at 12:30 AM Alexander Heger wrote: > for regular strings one can write > > "aaa" + "bbb" > > which also works for f-strings, r-strings, etc.; in regular expressions, > there is, e.g., parameter counting and references to numbered matches. How > would that be dealt with in a

Re: [Python-ideas] Add regex pattern literal p""

2018-12-28 Thread Steven D'Aprano
On Sat, Dec 29, 2018 at 04:29:32PM +1100, Alexander Heger wrote: > for regular strings one can write > > "aaa" + "bbb" > > which also works for f-strings, r-strings, etc.; in regular expressions, > there is, e.g., parameter counting and references to numbered matches. How > would that be dealt

Re: [Python-ideas] Add regex pattern literal p""

2018-12-28 Thread Alexander Heger
for regular strings one can write "aaa" + "bbb" which also works for f-strings, r-strings, etc.; in regular expressions, there is, e.g., parameter counting and references to numbered matches. How would that be dealt with in a compound p-string? Either it would have to re-compiled or not,

Re: [Python-ideas] Add regex pattern literal p""

2018-12-28 Thread Ma Lin
On 18-12-28 22:54, Joao S. O. Bueno wrote: Sorry for sounding over-reactive, but yes, this could make Python look like Perl. Yes, this may introduce Perl's style irreversibly, we need to be cautious about this. I'm thinking, if people ask these questions in their mind when reading a piece of

Re: [Python-ideas] Add regex pattern literal p""

2018-12-28 Thread Joao S. O. Bueno
I am a full -1 on this idea - > Two shortcomings: > > 1, Elevating a class in a module (re.Pattern) to language level, this > sounds not very natural. > This makes Python looks like Perl. > > 2, We can't use regex module as a drop-in replacement: import regex as re > IMHO, I would like to see

Re: [Python-ideas] Add regex pattern literal p""

2018-12-28 Thread Ma Lin
Reply to Stefan Behnel and Chris Angelico. On 18-12-27 22:42, Stefan Behnel wrote: >  >>> import pickle, re >  >>> p = re.compile("[abc]") >  >>> pickle.dumps(p) >  b'\x80\x03cre\n_compile\nq\x00X\x05\x00\x00\x00[abc]q\x01K \x86q\x02Rq\x03.' > > What this does, essentially, is to make the

Re: [Python-ideas] Add regex pattern literal p""

2018-12-27 Thread Steven D'Aprano
On Thu, Dec 27, 2018 at 05:47:46PM +, MRAB wrote: > On 2018-12-27 11:48, Ma Lin wrote: > [snip] > >2, We can't use regex module as a drop-in replacement: import regex as re > >IMHO, I would like to see regex module be adopted into stdlib after > >cutting off its "full case-folding" and "fuzzy

Re: [Python-ideas] Add regex pattern literal p""

2018-12-27 Thread MRAB
On 2018-12-27 11:48, Ma Lin wrote: [snip] 2, We can't use regex module as a drop-in replacement: import regex as re IMHO, I would like to see regex module be adopted into stdlib after cutting off its "full case-folding" and "fuzzy matching" features. I think that omitting full casefolding would

Re: [Python-ideas] Add regex pattern literal p""

2018-12-27 Thread Chris Angelico
On Fri, Dec 28, 2018 at 12:15 AM Ma Lin wrote: > > > It'd be good to know just how much benefit this precompilation > actually grants. > > As far as I know, Pattern objects in regex module can be pickled, don't > know if it's useful. > > >>> import pickle > >>> import regex > >>> p =

Re: [Python-ideas] Add regex pattern literal p""

2018-12-27 Thread Stefan Behnel
Ma Lin schrieb am 27.12.18 um 14:15: >> It'd be good to know just how much benefit this precompilation actually > grants. > > As far as I know, Pattern objects in regex module can be pickled, don't > know if it's useful. > import pickle import regex That's from the external regex

Re: [Python-ideas] Add regex pattern literal p""

2018-12-27 Thread Anders Hovmöller
> 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

Re: [Python-ideas] Add regex pattern literal p""

2018-12-27 Thread Ma Lin
> It'd be good to know just how much benefit this precompilation actually grants. As far as I know, Pattern objects in regex module can be pickled, don't know if it's useful. >>> import pickle >>> import regex >>> p = regex.compile('[a-z]') >>> b = pickle.dumps(p) >>> p = pickle.loads(b) >

Re: [Python-ideas] Add regex pattern literal p""

2018-12-27 Thread Chris Angelico
On Thu, Dec 27, 2018 at 10:49 PM Ma Lin wrote: > > We can use this literal to represent a compiled pattern, for example: > > >>> p"(?i)[a-z]".findall("a1B2c3") > ['a', 'B', 'c'] > > >>> compiled = p"(?<=abc)def" > >>> m = compiled.search('abcdef') > >>> m.group(0) > 'def' > > >>>

[Python-ideas] Add regex pattern literal p""

2018-12-27 Thread Ma Lin
We can use this literal to represent a compiled pattern, for example: >>> p"(?i)[a-z]".findall("a1B2c3") ['a', 'B', 'c'] >>> compiled = p"(?<=abc)def" >>> m = compiled.search('abcdef') >>> m.group(0) 'def' >>> rp'\W+'.split('Words, words, words.') ['Words', 'words', 'words', ''] This allows