I'm not sure if this question is being read correctly.
I already know what string formats are in Python.
Every single little detail, I already know.
Please stop directing me to questions about string types in Python.
This is a specific question that has to do with the problem string delimiter
in the body of a raw syntax construction.
I want to know why I can't use the raw syntax r"" or r'' form on this
For the record, I have read the docs and rules on raw strings.
The question is specific to escaping the delimiter within the raw string.
print "Raw targt string test = \"word's\""
v1 = r' "word\'s" ' # => "word\'s"
v2 = r" \"word's\" " # => \"word's\"
print "using r' ' syntax, variable contains " + v1
print "using r\" \" syntax, variable contains " + v2
if len(v1) == len(v2) :
print "length's are equal"
print "length's are NOT equal"
Raw targt string test = "word's"
using r' ' syntax, variable contains "word\'s"
using r" " syntax, variable contains \"word's\"
length's are NOT equal
To quote the Python FAQ, raw string literals in Python were "designed to ease creating input for processors (chiefly regular expression engines) that want to do their own backslash escape processing". Since the regex engine will strip the backslash in front of the quote character, Python doesn't need to strip it. This behavior will most likely never be changed since it would severely break backwards compatibility.
So yes, it is by design -- although it is quite confusing.
I want to know why I can't use the raw syntax r"" or r'' form on this raw string "word's" and have it exist in a variable just like this.
Python's raw string literals were not designed to be able to represent every possible string. In particular, the string
"' cannot be represented within
r''. When you use raw string literals for regex patterns, this is not a problem, since the patterns
\"\', are equivalent (that is, they all match the single string
However, note that you can write the string
"word's" using the triple-quoted raw string literal