最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to make regular expression match only Cyrillic bulgarian letters - Stack Overflow

programmeradmin7浏览0评论

Hello I want to replace all the letters from bylgarian alphabet with empty string I've seen this link How to match Cyrillic characters with a regular expression but it doesn't work for me

Here is what I've tried

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

doesn't work!

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

also nothing thanks for help;

Hello I want to replace all the letters from bylgarian alphabet with empty string I've seen this link How to match Cyrillic characters with a regular expression but it doesn't work for me

Here is what I've tried

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

doesn't work!

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

also nothing thanks for help;

Share Improve this question edited May 23, 2017 at 10:27 CommunityBot 11 silver badge asked Feb 2, 2013 at 7:08 Tania MarinovaTania Marinova 1,8988 gold badges42 silver badges67 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 13

Javascript doesn't support Unicode classes of the form \p{IsCyrillic}.

But, assuming the characters you want to replace are in the Unicode Cyrillic range 0400 - 04FF, you could use:

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

For example:

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

    console.log( newstr );    //  'hello'

I think that JavaScript RegEx does not support this syntax.

May be this will help?

XRegExp

Another way:

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

Where [А-я]+ is your alphabet.

发布评论

评论列表(0)

  1. 暂无评论