liveBook · Manning

Raw string literal

A raw string literal is a string-literal syntax that treats most backslashes and other contents literally, reducing ordinary escape processing.

How 3 Manning books explain it

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

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.