Does someone know where this JavaScript error comes from?
SyntaxError: expected expression, got '.'
I get this error when using a regular expression with a slash (escaped) like el.href.match(/video\/(.*)@/)[1]; as a string passed to a function like createTextNode, textContent or innerHTML.
This regex works when not stored as text. A regex without slash as text works, you can see my code example:
HTML:
<a style="display: none; width: 840px; height: 472px;" href="http://videos.francetv.fr/video/147338657@Info-web" id="catchup" class="video"></a>
JavaScript:
var el = document.getElementById("catchup");
var script = document.createElement("script");
var text = `
    (function() {
        var id = el.href.match(/video\/(.*)@/)[1];
        alert("test 4 - regex with slash as text: " + id);
    })();`; 
script.appendChild(document.createTextNode(text));      
document.getElementsByTagName("head")[0].appendChild(script);
Working and failing tests can be found here:
You can test it live on GitHub Pages (JSFiddle did not work in my case):
 
     
     
    