I have the following html code:
<input id="buttonClickOne" type="button" value="Click 1" @click="buttonOneClicked">
In my script I have a regular expression to pull the @click name and its value:
let arrEvents = source.match(/ @click="([^"]*)"/g);
I get the output that I'm expecting:
[" @click="buttonOneClicked""]
So I modified the reg exp so that I can have different events I may want to search for:
const arrEventTypes = ['@click'];
for(let event_type of arrEventTypes){
let reg = new RegExp(' ' + event_type + '="([^"]*)"', 'g');
let arrEvents = reg.exec(source);
...
}
But my output is different:
[" @click="buttonOneClicked"", "buttonOneClicked"]
If I look at the RegExp that I create it looks correct:
" @click="([^"]*)""
Am I missing something?
Solution
Thanks for the link. It makes more sense now. I started the expression version while I was coding but Touffy made a good point about using the DOMParser which actually worked better for my needs.