提问人:WayneF 提问时间:3/27/2023 最后编辑:WayneF 更新时间:3/28/2023 访问量:95
如何在 JavaScript [] 正则表达式中编码 &emdash UTF?
How to code &emdash UTF in JavaScript [] regular expressions?
问:
UTF 中的 HTML 是 ,十六进制被视为 。如何将其编码为正则表达式比较?(“如果这个,那么那个”)类型的比较?上面只是几个 ASCII 字符,但如何在正则表达式中将其编码为一个字符?&emdash;
—
1EFBBBFE280941
/[ ]/
这个概念可能吗?
编辑:仍然感到困惑,但我现在意识到我的一些困惑是 EF BB BF 是在我的十六进制查看器中添加的某种工件。它曾经位于十六进制列表的顶部,但它不在任何正在检查的数据字节中。—
我混淆了它的名字 Em Dash,但代码是,它的数据是 E2 80 94。我实际上在我自己的代码中使用它,认为它节省了一次查找。&emdash;
—
—
至于提供代码,我想是这样的:
HTML:
<div id="a12"> — — — — — -40.83 337.01 147.96 -31.27 -82.16 47.42 -ABC- 1 — 2 — 3 — 4</div>
The first part is Copy/Paste of the 11 years of Total Return entries
at https:/.www.morningstar.com/stocks/xnas/roku/price-fair-value
The 2nd part is the 3 HTML equivalents of the — character.
The goal is to remove all —
(to be replaced by "" ... there are other blank and tab there with it)
My Javascript testing:
var x = document.getElementById("a12");
var m = x.textContent;
var rgex = /u\2014/g;
//var rgex = /[u\2014]/g;
//var rgex = /\u{2014}\u/g ;
var n = rgex.test(m); //but test is false
m = m.replace(rgex, "");
alert( m + " " + n); //and string is unchanged
/u\2014/g 是我从阅读中尝试的,但它不起作用(也没有其他尝试)。
所以我的问题是,应该检测什么?—
编辑:FWIW,我想我明白了!
看起来做得很好。我以前试过,但一定有语法问题。var rgex = /\u2014/g;
并且还删除了制表符和空格(全部替换为分隔符的空格)。var rgex = /[\t \u2014]/g;
https://www.http://unicode.org/reports/tr18/ 对我的帮助,第 1.1 节说得很清楚。
答: 暂无答案
评论
—
E2 80 94
—
2014
1EFBBBFE280941
EFBBBF
并且是 '' (U+FEFF, Zero Width No-Break Space/BYTE ORDER MARK) 和 (U+2014, Em Dash) 的 UTF-8 字节序列。不清楚 1 是什么;请编辑您的问题,以提供一个最小的可重复示例。顺便说一句,没什么 - 也许你的意思是?E28094
—
&emdash;
—