Only one word in my code is highlighted
$(document).ready(function() {
let firstword = 'web';
let secondword = 'js';
$(".field.ConditionsAccept>.caption:contains('" + secondword + "'):contains('" + firstword + "')").each(function() {
var regex = new RegExp("(" + secondword + ")", 'g');
var regex2 = new RegExp("(" + firstword + ")", 'g');
$(this).html($(this).text().replace(regex, '<span class="word" style="text-decoration: underline">$1</span>'));
$(this).html($(this).text().replace(regex2, '<span class="word2" style="text-decoration: underline">$1</span>'));
});
});
.ConditionsAccept { width: 500px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="field ConditionsAccept">
<caption class="caption">Here is some web and js stuff</caption>
</table>