The problem
I have a large chunk of text in Hebrew (or any other language for that matter, except English).
Because the client is responsible for the input of all content sometimes he will sometimes enter English characters.
The website is in wordpress and the location where the client enters the text is the default content area, wysiwyg.
I need to find every English charcter/word and wrap it. Ignore English characters/words inside html tag "<>" and ignore and everything like this > OR ©, in this format &...;;
Example text
<div class="content">
<p>?????? ????? this000 as well ????? ?? ??, ????</p>
<p>??? ?????? ????, ???? ????</p>
<p>? ????? ?? ????, ?????? ????</p>
<p>????????. <a href="http://google.com">?????? ???? text ????? ??</a> ?????? ???? ??????</p>
<p>????? ?? ???, ?????? more text here ???? ?????</p>
<p> </p>
<p> </p>
</div>
Final result
Find and wrap every match with a span tag,
<p>?????? ????? this000 as well ????? ?? ??, ????</p>
Will become
<p>?????? ????? <span class="en">this000 as well</span> ????? ?? ??, ????</p>
And so on
My solution
<script>
const to_english_regex = /(?<!<[^>]*)([0-9]+)?[a-z_-]+([0-9s_-]+)?[a-z_-]+([0-9]+)?/ig
$('.to-english').html(function(_, html) {
return html.replace(to_english_regex, '<span style="font-family: futura;">$&</span>');
});
</script>
This seems to ignore all English inside the tags but not ignores &...; type of code.
Alos seems like this (?<!<[^>]*)
part causes the problems in IOS devices.
Any help would be greatly appreciated.
const to_english_regex = /(?<!<[^>]*)([0-9]+)?[a-z_-]+([0-9s_-]+)?[a-z_-]+([0-9]+)?/ig
let html = document.getElementById('content').innerHTML
document.getElementById('result').innerHTML = "Result:<br><pre>" + html.replace(to_english_regex, '<span style="font-family: futura;">$&</span>') + "</pre>";
#result {background-color: lightblue;}
<div id="content">
<p>?????? ????? this000 as well ????? ?? ??, ????</p>
<p>??? ?????? ????, ???? ????</p>
<p>? ????? ?? ????, ?????? ????</p>
<p>????????. <a href="http://google.com">?????? ???? text ????? ??</a> ?????? ???? ??????</p>
<p>????? ?? ???, ?????? more text here ???? ?????</p>
<p> </p>
<p> </p>
</div>
<div id="result">
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…