title: Python Regex escape operator \ in substitutions & raw strings
body: <p>I don't understand the logic in the functioning of the scape operator \ in python regex together with r' of raw strings.
  Some help is appreciated.</p>
  
  <p>code:</p>
  
  <pre><code>import re
  text=' esto  .es  10  . er - 12 .23 with [  and.Other ] here is more ; puntuation'
  print('text0=',text)
  text1 = re.sub(r'(\s+)([;:\.\-])', r'\2', text)
  text2 = re.sub(r'\s+\.', '\.', text)
  text3 = re.sub(r'\s+\.', r'\.', text)
  print('text1=',text1)
  print('text2=',text2)
  print('text3=',text3)
  </code></pre>
  
  <p>The theory says:
  backslash character ('\') to indicate special forms or to allow special characters to be used without invoking their special meaning.</p>
  
  <p>And as far as the link provided at the end of this question explains, r' represents a raw string, i.e. there is no special meaning for symbols, it is as it stays.</p>
  
  <p>so in the above regex I would expect text2 and text3 to be different, since the substitution text is '.' in text 2, i.e. a period, whereas (in principle) the substitution text in text 3 is r'.' which is a raw string, i.e. the string as it is should appear, backslash and period. But they result in the same:</p>
  
  <p>The result is:</p>
  
  <pre><code>text0=  esto  .es  10  . er - 12 .23 with [  and.Other ] here is more ; puntuation
  text1=  esto.es  10. er- 12.23 with [  and.Other ] here is more; puntuation
  text2=  esto\.es  10\. er - 12\.23 with [  and.Other ] here is more ; puntuation
  text3=  esto\.es  10\. er - 12\.23 with [  and.Other ] here is more ; puntuation
  #text2=text3 but substitutions are not the same r'\.' vs '\.'
  </code></pre>
  
  <p>It looks to me that the r' does not work the same way in substitution part, nor the backslash. On the other hand my intuition tells me I am missing something here.</p>
  
  <p>EDIT 1:
  Following @Wiktor Stribiżew comment.
  He pointed out that (following his link):</p>
  
  <pre><code>import re
  print(re.sub(r'(.)(.)(.)(.)(.)(.)', 'a\6b', '123456'))
  print(re.sub(r'(.)(.)(.)(.)(.)(.)', r'a\6b', '123456'))
  # in my example the substitutions were not the same and the result were equal
  # here indeed r' changes the results
  </code></pre>
  
  <p>which gives:</p>
  
  <pre><code>ab
  a6b
  </code></pre>
  
  <p>that puzzles me even more.  </p>
  
  <p>Note:
  I read <a href="https://stackoverflow.com/questions/12871066/what-exactly-is-a-raw-string-regex-and-how-can-you-use-it">this</a> stack overflow question about raw strings which is super complete. Nevertheless it does not speak about substitutions</p>