I do have following string:
\\\"lengthSeconds\\\":\\\"2664\\\"
which I would like to match with this regexp:
Regex::new(\"lengt
By using r#..#, you treat your string as a raw string and hence do not process any escapes. However, since backslashes are special characters in Regex, the Regex expression itself still requires you to escape backslashes. So this
Regex::new(r#"\\"lengthSeconds\\":\\"(\d+)\\""#)
is what you want.
Alternatively, you could write
Regex::new("\\\\\"lengthSeconds\\\\\":\\\\\"(\\d+)\\\\\"").unwrap();
to yield the same result.
See this example on Rust Playground