-2

Pretty much as question states- I have a code that finds sentences in a big string using regex- findall(). It then uses this sentence later, however when it uses it it puts a backslash infront of any apostrophe, for example Today's becomes Today\'s. Why is this happening, and how can I stop this happening?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
user3662991
  • 1,083
  • 1
  • 11
  • 11

2 Answers2

1

It's called escaping a string. When you use " or ' inside of a string use \ to avoid lexical syntax errors. I believe there is a method that removes the escape character from a string if that's what you'd like to do.

uhfocuz
  • 3,178
  • 2
  • 13
  • 27
0

The backslash denotes a so called escape sequence, which basically tells python that this character has to be interpreted differently from a "normal" ' character (which would signal the beginning or end of a string for the interpreter).

dudenr33
  • 1,119
  • 1
  • 10
  • 26