Replace

Replace color codes

HTML

<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <title>Ranks</title>
    <!--Import datatables-->
    <link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css">
    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
  </head>

  <body>
    <table id="ranks" class="display"></table>
  </body>

</html>

CSS

#dark_red {
    color: #AA0000;
}

#red {
    color: #FF5555;
}

#gold {
    color: #FFAA00;
}

#yellow {
    color: #FFFF55;
}

#dark_green {
    color: #00AA00;
}

#green {
    color: #55FF55;
}

#aqua {
    color: #55FFFF;
}

#dark_aqua {
    color: #00AAAA;
}

#dark_blue {
    color: #0000AA;
}

#blue {
    color: #5555FF;
}

#light_purple {
    color: #FF55FF;
}

#dark_purple {
    color: #AA00AA;
}

#white {
    color: #FFFFFF;
    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}

#gray {
    color: #AAAAAA;
}

#dark_gray {
    color: #555555;
}

#black {
    color: #000000;
}

#bold {
    font-weight: bold;
}

#italic {
    font-style: italic;
}

#underline {
    text-decoration: underline;
}

#strikethrough {
    text-decoration: line-through;
}

JavaScript

let dataSet = [{name: "title1", lore: ["&fline 1","&c&lline2"]}]
let codes = ["&4", "&c", "&6", "&e", "&2", "&a", "&b", "&3", "&1", "&9", "&d", "&5", "&f", "&7", "&8", "&0", "&l", "&m", "&n", "&o"];

$(document).ready(async function () {
        $('#ranks').DataTable({
            data: dataSet,
            columns: [
            	{data: `name`},
              {
                    data: 'lore',
                    render: function (data) {
                        let j = 0;
                        data.forEach(item => {
                        numCodes = countOccurrences(item.toString(), `&`);
                            for (let i = 0; i < numCodes; i++) {

                                let contain = false;
                                codes.some(element => {
                                    if (item.includes(element)) {
                                        contain = true;
                                    }
                                });
                                if (contain) {
                                    item = replaceColorCodes(item.toString().trim());
                                }
                                //console.log(item);
                            }
                            data[j] = item;
                            j++;
                        });
                        //console.log("Sending data to table: " + data);
                        return data.join(`<br>`);
                    }
                }
            ]
        });
});

function countOccurrences(str, value) {
    let regExp = new RegExp(value, "gi");
    return (str.match(regExp) || []).length;
}

function replaceColorCodes(text) {
    if ( (text.indexOf(`&`) !== -1) && text.indexOf(`&`) <= (text.length - 1)) {
        let locStart = text.indexOf(`&`);
        if ((locStart !== -1) && (locStart !== null) && (locStart !== undefined)) {
            let code = text.charAt(text.indexOf(`&`) + 1);
            let start = text.substring(0,...