use strict;
my $str = '// 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;';
my $regex = qr/[`\\]|\${/mp;
my $subst = '\\\\$&';
my $result = $str =~ s/$regex/$subst/rg;
print "The result of the substitution is' $result\n";
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 Perl, please visit: http://perldoc.perl.org/perlre.html