Skip to content

Commit c03b82d

Browse files
authored
Merge pull request #9207 from dalexeev/gds-clarify-r-string-docs
GDScript: Clarify raw string literals documentation
2 parents c2092ed + 60befd7 commit c03b82d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tutorials/scripting/gdscript/gdscript_basics.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,14 +429,22 @@ A string enclosed in quotes of one type (for example ``"``) can contain quotes o
429429
two consecutive quotes of the same type (unless they are adjacent to the string edges).
430430

431431
**Raw string literals** always encode the string as it appears in the source code.
432-
This is especially useful for regular expressions. Raw strings do not process escape sequences,
433-
but you can "escape" a quote or backslash (they replace themselves).
432+
This is especially useful for regular expressions. A raw string literal doesn't process escape sequences,
433+
however it does recognize ``\\`` and ``\"`` (``\'``) and replaces them with themselves.
434+
Thus, a string can have a quote that matches the opening one, but only if it's preceded by a backslash.
434435

435436
::
436437

437438
print("\tchar=\"\\t\"") # Prints ` char="\t"`.
438439
print(r"\tchar=\"\\t\"") # Prints `\tchar=\"\\t\"`.
439440

441+
.. note::
442+
443+
Some strings cannot be represented using raw string literals: you cannot have an odd number
444+
of backslashes at the end of a string or have an unescaped opening quote inside the string.
445+
However, in practice this doesn't matter since you can use a different quote type
446+
or use concatenation with a regular string literal.
447+
440448
GDScript also supports :ref:`format strings <doc_gdscript_printf>`.
441449

442450
Annotations

0 commit comments

Comments
 (0)