Different behaviour of regexp in 3.6.0b2
Ned Batchelder
ned at nedbatchelder.com
Fri Oct 14 12:58:20 EDT 2016
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'
--Ned.
More information about the Python-list
mailing list