This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: '\' problem in re.sub
Type: Stage:
Components: Extension Modules Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: bos, georg.brandl, ilan29
Priority: normal Keywords:

Created on 2006-07-07 01:03 by ilan29, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg29087 - (view) Author: ilan29 (ilan29) Date: 2006-07-07 01:03
#! /usr/bin/env python
import re

# Pattern only to match character 'b'
p = re.compile('b')

# Replace 'b' with SINGLE literal backslash
print p.sub( '\\', 'b', 1 )


I'm running:
   Python 2.4.3 (#1, Jun 11 2006, 12:01:42) 
   [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2

When starting the progam it raises:
sre_constants.error: bogus escape (end of line)
msg29088 - (view) Author: Bryan O'Sullivan (bos) Date: 2006-07-07 06:21
Logged In: YES 
user_id=28380

Your code is wrong.  Both Python and re interpret
backslashes, and you're not passing enough backslashes in
for re to see two.
msg29089 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-07-07 07:47
Logged In: YES 
user_id=849994

bos is right.
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43629
2006-07-07 01:03:21ilan29create