I'm trying to filter out this specific pattern out of a string
myAttribute="myValue"
But I can't seem to figure out on how to ignore the quotes / symbols found inside the 'main' quotes.. If this doesn't make sense, here are few examples:
Examples:
1) onclick="console.log("Hello world"));" < must ignore the double quotes in onclick, must return match 1: onclick, match 2: console.log("Hello world"));
2) onclick='console.log('Hello world'));' < must ignore the single quotes in onclick, must return match 1: onclick, match 2: console.log('Hello world'));
3) onclick="console.log('Hello world'));" < must return match 1: onclick, match 2: console.log('Hello world'));
4) onclick="console.log(\"Hello world\"));" < must return match 1: onclick, match 2: console.log(\"Hello world\"));
5) onclick="document.querySelector('[data-uniqueid=\"my-id\"]').outerHTML = '';"
^ must return (NOTE THE '=' SYMBOL) match 1: onclick, match 2: document.querySelector('[data-uniqueid=\"my-id\"]').outerHTML = '';
This is my current Regular Expression:
(\S+)=["'].*["']$
NOTE: It actually has to ignore every single character found between the 'main' quotes and support multiple attributes (so onclick="myValue" onmouseover="alert('hello world!');") as one string).
Aucun commentaire:
Enregistrer un commentaire