Raw string literal
A raw string literal is a string-literal syntax that treats most backslashes and other contents literally, reducing ordinary escape processing.
The Quick Python Book, Fourth Edition
A raw string literal is a Python string literal in which backslashes are generally treated as literal characters rather than introducing escape sequences.
- How it is used
- Prevents Python from interpreting backslashes too early in regex patterns and Python code written to a file.
- How deep it goes
- Explains prefix syntax, quoting options, string comparisons, and two-stage regex interpretation, without detailing every raw-string edge case.
- Examples
- Contrasts printed raw and ordinary strings, compiles a regex matching a literal backslash, and repairs a generated module.
- What you can do after
- Apply it via Python’s `re` module to write patterns without extra string-level escaping, or preserve backslashes in generated code.
Read how The Quick Python Book, Fourth Edition explains raw string literal →
Natural Language Processing in Action, Second Edition
A Python string literal in which backslashes are preserved rather than normally interpreted as escape sequences.
- How it is used
- Simplifies writing regular expressions by preserving backslashes for the regular-expression parser.
- How deep it goes
- Defines backslash preservation and contrasts raw patterns with doubled escapes, without detailing string-parser internals.
- Examples
- Uses whitespace matching, literal curly braces, greeting patterns, and compiled regular expressions as examples.
- What you can do after
- Apply raw string literals to write more readable Python regular-expression patterns with unmodified backslashes.
Read how Natural Language Processing in Action, Second Edition explains raw string literal →
100 C++ Mistakes and How to Avoid Them
A raw string is a C++ string literal whose contents are written without interpreting ordinary escape sequences.
- How it is used
- Uses raw string literals to keep regular-expression patterns readable when C++ escaping would obscure the intended match.
- How deep it goes
- Explains R"(... )" delimiters and contrasts raw and escaped backslash patterns through concrete code.
- Examples
- Uses escaped and raw patterns for matching backslashes, plus an email-validation regular expression.
- What you can do after
- Apply it via C++ syntax to write more readable regular-expression patterns.
Read how 100 C++ Mistakes and How to Avoid Them explains raw string literal →
Related concepts
- string literalkind of · A string literal is source-code notation that directly represents a string value.
- stringkind of · A string is a programming-language value representing an ordered sequence of characters or character units as text.
- regular expressionuses · A formal pattern notation that describes sets of strings and enables text to be matched, searched, extracted, or transformed.
- escape sequencecontrasts with · An escape sequence is source notation, typically using an escape marker, that represents a character or control value or changes how characters are interpreted.
- newlinecontrasts with · A newline is a character or character sequence that marks the boundary between consecutive lines of text.
- f-stringcontrasts with · An f-string is a Python formatted string literal that evaluates embedded expressions and inserts their formatted values into the resulting string.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


