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
- Uses raw strings to preserve backslashes in regular expressions and generated Python code.
- How deep it goes
- Explains prefix and quoting forms, compares string values, and traces Python and regex escaping separately.
- Examples
- Compares tab escapes, compiles a literal-backslash pattern, and writes a module containing a newline escape.
- What you can do after
- Apply raw string literals with re.compile and when writing Python code to a file.
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
- Clarifies regular-expression patterns by separating their characters from C++ string-escape syntax.
- How deep it goes
- Defines the opening and closing delimiters and demonstrates their effect through a pattern comparison.
- Examples
- Compares ordinary and raw string literals for a pattern matching two backslashes and uses a regular expression for email validation.
- What you can do after
- Understand how raw strings make regular-expression patterns easier to read without C++ escape notation.
Read how 100 C++ Mistakes and How to Avoid Them explains raw string literal →
Also covered in
- Learn Go with Pocket-Sized Projects
- Refactoring to Rust
- Learn C++ by Example
- .NET in Action, Second Edition
- Python How-To
- Tiny Python Projects: Learn coding and testing with puzzles and games
- Julia as a Second Language
- Go by Example
- Go in Action, Second Edition
What to know first
- string literalA string literal is a fixed sequence of text characters written directly in a programming or data-language expression as a string value, rather than computed from other data.
- escape sequenceAn escape sequence is source notation using a marker to change how following characters are interpreted, often representing a special character or control value or making syntax literal.
- regular expressionA regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
- backslashA backslash is the character \ commonly used in programming and text syntaxes to introduce an escape sequence or alter the interpretation of a following character.
Related concepts
- string literalkind of · A string literal is a fixed sequence of text characters written directly in a programming or data-language expression as a string value, rather than computed from other data.
- stringkind of · A string is a programming-language value representing textual data as an ordered sequence of characters or encoded units.
- regular expressionuses · A regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
- literalkind of · A literal is a language construct that directly denotes a fixed value or specifies an exact value permitted by a type.
- escape sequencecontrasts with · An escape sequence is source notation using a marker to change how following characters are interpreted, often representing a special character or control value or making syntax literal.
- newlinecontrasts with · A newline is a character or character sequence that marks the boundary between consecutive lines of text.
Questions about raw string literal
What is raw string literal?
A raw string literal is a string-literal syntax that treats most backslashes and other contents literally, reducing ordinary escape processing.
Which Manning books explain raw string literal?
The Quick Python Book, Fourth Edition, Natural Language Processing in Action, Second Edition and 100 C++ Mistakes and How to Avoid Them.
What should I know before learning raw string literal?
Manning books that teach raw string literal usually introduce string literal, escape sequence, regular expression and backslash first.
What is the difference between raw string literal and escape sequence?
A raw string literal is a string-literal syntax that treats most backslashes and other contents literally, reducing ordinary escape processing. An escape sequence is source notation using a marker to change how following characters are interpreted, often representing a special character or control value or making syntax literal.
What is raw string literal a kind of?
Raw string literal is a kind of string literal. A string literal is a fixed sequence of text characters written directly in a programming or data-language expression as a string value, rather than computed from other data.
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.


