user6599829
user6599829

Reputation:

Doubling slash with re.findall - Python

I wonder why re.findall returns a string by adding a escape slash in front of each slash. Can we force it to return a raw string that is without this doubling slash ?

Example

src='on <p>essia \( de faire \)</p>'
src = re.findall(r'<p>(.*?)</p>',src)
print(src)

It returns:

['essia \\( de faire \\)']

But I would like to return:

['essia \( de faire \)']

Upvotes: 0

Views: 246

Answers (1)

gonczor
gonczor

Reputation: 4146

It's because it prints entire list. Print its elements to get desired output.

In [1]: import re

In [2]: src='on <p>essia \( de faire \)</p>'
   ...:

In [3]: src = re.findall(r'<p>(.*?)</p>',src)

In [4]: print(src)
['essia \\( de faire \\)']

In [5]: print(src[0])
essia \( de faire \)

Upvotes: 1

Related Questions