// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r"(?m)[`\\]|\${").unwrap();
let string = "// source https://stackoverflow.com/a/75688937/6404439
import React from 'react';
import SyntaxHighlighter from 'react-syntax-highlighter';
import { a11yDark } from 'react-syntax-highlighter/dist/esm/styles/hljs';
const CodeBlock: React.FC<{ codestring: string }> = ({ codestring }) => {
return (
<SyntaxHighlighter
language=\"javascript\"
style={a11yDark}
showLineNumbers>
{codestring}
</SyntaxHighlighter>
);
};
function App() {
var code = `function $initHighlight(block, cls) {
try {
if (cls.search(/\\bno\\-highlight\\b/) != -1)
return process(block, true, 0x0F) +
\\` class=\"\\${cls}\"\\`;
} catch (e) {
/* handle exception */
}
for (var i = 0 / 2; i < classes.length; i++) {
if (checkCondition(classes[i]) === undefined)
return /\\d+[\\s/]/g;
}
return 0xA;
}
export $initHighlight;`;
return (
<div className=\"w-1/2 bg-blue-700\">
<CodeBlock codestring={code} />
</div>
);
}
export default App;";
let substitution = "\\\\$&";
// result will be a String with the substituted value
let result = regex.replace_all(string, substitution);
println!("{}", result);
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Rust, please visit: https://docs.rs/regex/latest/regex/