Shubham Jangid
Shubham Jangid

Reputation: 33

python regex: unexpected character after line continuation character

import re
def preprocessor(text):
    text = re.sub('<[^>]*>', '', text)
    emoticons = re.findall('(?::|;|=)(?:-)?(?:\)|\(|D|P)', text)
    text = re.sub('[\W]+', ' ', text.lower()) + \'.join(emoticons).replace('-', '')
    return text

I am getting an error in line 5 saying "unexpected character after line continuation character". Please, somebody help me out.

Upvotes: 1

Views: 727

Answers (1)

andrew_reece
andrew_reece

Reputation: 21274

Your join() statement is not properly formed. Because you have a bare \, the interpreter thinks you're invoking the line continuation character, e.g.:

print("a \
b")
# a b

If you want to join on \, use:

print("\\".join(['a','b'])) 
# a\b

In your case:

 '\\'.join(emoticons)

Upvotes: 3

Related Questions