As mentioned, I am trying to convert some html tags to other custom tags with RegExp.
My solution is not worked in nested tag as below:
Solution 1:
var str = '<span style=\"font-size: x-large;\"><span style=\"color: red;\">HELLO WORLD</span></span>';
var txt = str.replace(/<span style=\"(font-size|color): (.*?);\">(.*?)<\/span>/gim,"[$2]$3[/$2]");
Excepted result:
[x-large][red]HELLO WORLD[/red][/x-large]
Actual result:
[x-large]<span style="color: red;">[/x-large]</span>
Solution 2:
var str = '<span style=\"font-size: x-large;\"><span style=\"color: red;\">HELLO WORLD</span></span>';
var txt = str.replace(/<span style=\"(font-size|color): (.*?);\">(.*?)<\/span>/gim,"[$2]$3[/$2]");
txt = txt.replace(/<span style=\"(font-size|color): (.*?);\">(.*?)<\/span>/gim,"[$2]$3[/$2]");
Excepted result:
[x-large][red]HELLO WORLD[/red][/x-large]
Actual result:
[x-large][red]HELLO WORLD[/x-large][/red]