admin管理员组文章数量:1297002
I have this html (The text in Hebrew):
בדיקה בדיקה בדיקה‎ניסיון ניסיון ניסיון
I want to remove the (‎
) by replacing it with space.
I tried to using regex like:
$('#result').html($('#test').html().replace(/‎/, ' '));
$('#result2').html($('#test2').html().replace(/©/, ' '));
<script src=".1.1/jquery.min.js"></script>
<div id="test">
בדיקה בדיקה בדיקה‎ניסיון ניסיון ניסיון
</div>
<hr />
<div id="test2">
בדיקה בדיקה בדיקה©ניסיון ניסיון ניסיון
</div>
<hr />
<div id="result"></div>
<hr />
<div id="result2"></div>
I have this html (The text in Hebrew):
בדיקה בדיקה בדיקה‎ניסיון ניסיון ניסיון
I want to remove the (‎
) by replacing it with space.
I tried to using regex like:
$('#result').html($('#test').html().replace(/‎/, ' '));
$('#result2').html($('#test2').html().replace(/©/, ' '));
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="test">
בדיקה בדיקה בדיקה‎ניסיון ניסיון ניסיון
</div>
<hr />
<div id="test2">
בדיקה בדיקה בדיקה©ניסיון ניסיון ניסיון
</div>
<hr />
<div id="result"></div>
<hr />
<div id="result2"></div>
I added the copy example to show that I can replace the copy character because it's visible symbol. But How can I replace the left to right symbol?
Share Improve this question asked Aug 24, 2015 at 7:08 Mosh FeuMosh Feu 29.3k18 gold badges93 silver badges141 bronze badges 2- 2 Great example of how to ask a question (and it's an interesting one, too) – Thilo Commented Aug 24, 2015 at 7:12
-
Try
$('#result').html($('#test').html().replace(/\u200E/, ' '));
– Wiktor Stribiżew Commented Aug 24, 2015 at 7:13
1 Answer
Reset to default 10When you retrieve the HTML, apparently the LTR mark isn't being turned into a character entity, it's just Unicode character 200E
.
So to allow for browsers that make it an entity and ones that don't, use an alternation between <r;
and \u200E
:
var html = $('#test').html();
var rep = html.replace(/‎|\u200E/gi, ' ');
$('#result').html(rep);
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="test">
בדיקה בדיקה בדיקה‎ניסיון ניסיון ניסיון
</div>
<hr />
<div id="result"></div>
There I've also allowed for the entity to be in either upper case (<R;
) or lower case (<r;
), and added the g
flag to replace it throughout the entire string (remove the g
if you only wanted to replace the first one).
本文标签: htmlLeft to right mark in regex (amp8206) JavaScriptStack Overflow
版权声明:本文标题:html - Left to right mark in regex (&#8206;) JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741648234a2390316.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论