从 javascript 中的字符串中删除 Niqqud
remove Niqqud from string in javascript
我遇到了此处描述的确切问题:
Have been struggling to remove niqqud ( diacritical signs used to represent vowels or distinguish between alternative pronunciations of letters of the Hebrew alphabet). I have for instance this variable: sample1 <- "הֻסְמַק"
And i cannot find effective way to remove the signs below the letters.
但在我的情况下,我必须在 javascript 中执行此操作。
只是你的正则表达式有点问题。请尝试以下操作:
const input = "הֻסְמַק";
console.log(input)
console.log(input.replace(/[\u0591-\u05C7]/g, ''));
/*
$ node index.js
הֻסְמַק
הסמק
*/
nj_的回答很好
补充一点(因为我没有足够的声望点直接评论)-
[\u0591-\u05C7]
可能刷的太宽了。在此处查看相关 table:https://en.wikipedia.org/wiki/Unicode_and_HTML_for_the_Hebrew_alphabet#Compact_table
行 059x
和 05AX
用于 t'amim(accents/cantillation 标记)。
Niqud 本身在 05Bx
和 05Cx
.
行中
正如 Avraham 评论的那样,如果 2 个单词由 makaf (05BE
) 连接,你可以 运行 进入一个问题,然后通过删除它你将得到 运行 -关于文字。
如果只想删除 t'amim 但保留 nikud,请使用 /[\u0591-\u05AF]/g
。如果您想避免 Avraham 提出的问题,您有 2 个选择 - 要么保留 maqaf,要么用破折号替换它:
//keep the original makafim
const input = "כִּי־טוֹב"
console.log(input)
console.log(input.replace(/([\u05B0-\u05BD]|[\u05BF-\u05C7])/g,""));
//replace makafim with dashes
console.log(input.replace(/\u05BE/g,"-").replace(/[\u05B0-\u05C7]/g,""))
/*
$ node index.js
כִּי־טֽוֹב
כי־טוב
כי-טוב
*/
我遇到了此处描述的确切问题:
Have been struggling to remove niqqud ( diacritical signs used to represent vowels or distinguish between alternative pronunciations of letters of the Hebrew alphabet). I have for instance this variable: sample1 <- "הֻסְמַק"
And i cannot find effective way to remove the signs below the letters.
但在我的情况下,我必须在 javascript 中执行此操作。
只是你的正则表达式有点问题。请尝试以下操作:
const input = "הֻסְמַק";
console.log(input)
console.log(input.replace(/[\u0591-\u05C7]/g, ''));
/*
$ node index.js
הֻסְמַק
הסמק
*/
nj_的回答很好
补充一点(因为我没有足够的声望点直接评论)-
[\u0591-\u05C7]
可能刷的太宽了。在此处查看相关 table:https://en.wikipedia.org/wiki/Unicode_and_HTML_for_the_Hebrew_alphabet#Compact_table
行 059x
和 05AX
用于 t'amim(accents/cantillation 标记)。
Niqud 本身在 05Bx
和 05Cx
.
正如 Avraham 评论的那样,如果 2 个单词由 makaf (05BE
) 连接,你可以 运行 进入一个问题,然后通过删除它你将得到 运行 -关于文字。
如果只想删除 t'amim 但保留 nikud,请使用 /[\u0591-\u05AF]/g
。如果您想避免 Avraham 提出的问题,您有 2 个选择 - 要么保留 maqaf,要么用破折号替换它:
//keep the original makafim
const input = "כִּי־טוֹב"
console.log(input)
console.log(input.replace(/([\u05B0-\u05BD]|[\u05BF-\u05C7])/g,""));
//replace makafim with dashes
console.log(input.replace(/\u05BE/g,"-").replace(/[\u05B0-\u05C7]/g,""))
/*
$ node index.js
כִּי־טֽוֹב
כי־טוב
כי-טוב
*/