Different behaviour of regexp in 3.6.0b2

Lele Gaifax lele at metapensiero.it
Fri Oct 14 13:42:29 EDT 2016


Ned Batchelder <ned at nedbatchelder.com> writes:

> On Friday, October 14, 2016 at 12:50:44 PM UTC-4, Lele Gaifax wrote:
>> Chris Angelico <rosuav at gmail.com> writes:
>> 
>> > There's a shift as of 3.6 to make unrecognized alphabetic escapes into
>> > errors, or at least warnings.
>> 
>> But we are talking about raw strings here, specifically r'\s+'.
>> 
>> I agree that with plain strings it's a plus.
>
> The raw string means the regex engine gets three characters: backslash,
> s, plus.  It then has to decide what backslash-s means. In 3.6, this is
> an error.  You'll need to escape the backslash for the regex engine:
>
>     >>> re.sub(r'\s+', r'\\s+', 'foo bar')
>     'foo\\s+bar'

Thanks for the clarification.

I tested the above syntax and works flawlessly on 2.7, 3.5 and 3.6b2, and I
will therefore suggest it on https://github.com/dbcli/pgcli/issues/595.

bye, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele at metapensiero.it  |                 -- Fortunato Depero, 1929.




More information about the Python-list mailing list