liveBook · Manning

Raw string literal

As explained in 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.

A raw string literal writes its contents without interpreting ordinary C++ escape sequences. It starts with R"( and ends with )", making regular-expression patterns easier to read when backslashes would otherwise become difficult to distinguish from C++ formatting. section 4.8

Compare escaped and raw patterns

To match two backslashes, an escaped string requires std::string pattern = "\\\\";, while the raw form is std::string pattern = R"(\\)";. The raw version shows the characters being matched more directly. In a regular expression, necessary escapes still matter: an escaped period means “match a period” rather than any single character. section 4.8

How 100 C++ Mistakes and How to Avoid Them covers it

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.
How it connects
Connects raw string literals to regular expressions, escape sequences, and email validation.

Also explained in

Compare how 3 books explain raw string literal →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 C++ Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.