I was trying to create a 'components' system, similar to many JS frameworks. I am new to RegEx but I made something that should work for me:
/\<([A-Z])([A-Za-z])*( ?\/)?\>/g
Now, I tried to search the file for this RegEx, and replace it with the correct component,
var content = "<p>file content</p><Test />";
var components = { Test: "<b>test component</b>" };
content.split(/\<([A-Z])([A-Za-z])*( ?\/)?\>/g).forEach((comp) => {
newCont = content.replace(
comp,
components[comp.substr(1, comp.length - 1)]
);
});
but it doesn't work.
I want the code to remove all instances of <Test />
or similar, and replace them with my definition of it from components
(eg. change content
to "<p>file content</p><b>test component</b>"
).