How to delete vertical line from string
beautifulsoup, python
Solution
You need to treat the regex as a raw string:
s = 'How to run very fast | running.com'
s = re.sub(r'\|', '', s)
>>> print s
How to run very fast running.com
Demo: http://repl.it/R8m
Problem
For some reason I can't delete the vertical bar from a string. This string was extracted from an html tag (BeautifulSoup 4). The string comes from the title meta tag of a site. Example input: 'How to run very fast | running.com' By the if statement, the string still contains the |, but it is not detected in name and never enters the if statement... ``` name = title.text.encode('ascii', 'ignore').strip() #remove everything after | because often it is SEO stuff name = re.sub('\|', '', name) #fails if "|" in name: lineIndex = name.index('|') name = name[:lineIndex] ```