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">   
בדיקה בדיקה בדיקה&lrm;ניסיון ניסיון ניסיון
  </div>
<hr />
<div id="test2">   
בדיקה בדיקה בדיקה&copy;ניסיון ניסיון ניסיון
  </div>
<hr />
<div id="result"></div>
<hr />
<div id="result2"></div>

I have this html (The text in Hebrew):

בדיקה בדיקה בדיקה&lrm;ניסיון ניסיון ניסיון

I want to remove the (&lrm;) by replacing it with space.

I tried to using regex like:

$('#result').html($('#test').html().replace(/&lrm;/, ' '));
$('#result2').html($('#test2').html().replace(/©/, ' '));
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="test">   
בדיקה בדיקה בדיקה&lrm;ניסיון ניסיון ניסיון
  </div>
<hr />
<div id="test2">   
בדיקה בדיקה בדיקה&copy;ניסיון ניסיון ניסיון
  </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
Add a ment  | 

1 Answer 1

Reset to default 10

When 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 &ltr; and \u200E:

var html = $('#test').html();
var rep = html.replace(/&lrm;|\u200E/gi, ' ');
$('#result').html(rep);
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="test">   
בדיקה בדיקה בדיקה&lrm;ניסיון ניסיון ניסיון
</div>
<hr />
<div id="result"></div>

There I've also allowed for the entity to be in either upper case (&LTR;) or lower case (&ltr;), 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