10

您好,我想用空字符串替换所有来自 bylgarian 字母的字母我已经看到了这个链接 How to match Cyrillic characters with a regular expression 但它对我不起作用

这是我尝试过的

1. var newstr = strInput.replace(/[\p{IsCyrillic}]/gi, '');

不工作!

2. var newstr = strInput.replace(/[\p{Letter}]/gi, '');

也没什么,谢谢你的帮助;

4

3 回答 3

13

Javascript 不支持 Unicode 类的形式\p{IsCyrillic}

但是,假设您要替换的字符在 Unicode Cyrillic范围 0400 - 04FF 中,您可以使用:

newstr = strInput.replace( /[\u0400-\u04FF]/gi, '' ); 

例如:

    var strInput = 'уфхцчшщъhelloЁЂЃЄрстыьэю',
        newstr = strInput.replace( /[\u0400-\u04FF]/gi, '' ); 

    console.log( newstr );    //  'hello'
于 2013-02-02T11:04:04.697 回答
2

我认为 JavaScript RegEx 不支持这种语法。

可能这会有所帮助吗?

正则表达式

于 2013-02-02T07:31:50.160 回答
1

其他方式:

Pattern.compile("[А-я]+", Pattern.UNICODE_CHARACTER_CLASS).matcher(strInput ).replaceAll("") ;

[А-я]+你的字母在哪里。

于 2016-03-19T21:01:52.043 回答