0

The main idea of raw string literal, as they wrote here, is to avoid the excessive number of backslases. The main idea of regular expressions is to make a search for substring clear. This is why I use regular expressions and raw string literal. Please help me write a regular expression that contains a list of quotes.

rexp = '\\$\\{[\\\\\\w]+\\(.*\\)\\[["\'`]\\]\\}'
print(rexp, len(rexp))

rexp1 = r'\$\{[\\\w]+\(.*\)\[["\'`]\]\}'
print(rexp1, len(rexp1))
\$\{[\\\w]+\(.*\)\[["'`]\]\} 28
\$\{[\\\w]+\(.*\)\[["\'`]\]\} 29
Alexander
  • 51
  • 5
  • @YevhenKuzmovych Did you try that yourself? The output contains two backslashes. I don't understand your comment... – John Gordon Sep 15 '22 at 18:23
  • @JohnGordon Right, pardon me. This works correct only for normal strings. – Yevhen Kuzmovych Sep 15 '22 at 18:26
  • 1
    There is _no_ method to include a backslash at the end of a raw string literal. However, you can have one at the end of a regular string literal: `"foo\\"`. If you really want to use a raw string for other reasons, append a regular string to it: `r"foo\bar\baz" + "\\"`. – ChrisGPT was on strike Sep 15 '22 at 18:59

0 Answers0