Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make regular expression match only Cyrillic bulgarian letters

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;

like image 735
Tania Marinova Avatar asked Feb 02 '13 07:02

Tania Marinova


3 Answers

Another way:

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

Where [А-я]+ is your alphabet.

like image 137
Suvitruf - Andrei Apanasik Avatar answered Nov 03 '22 01:11

Suvitruf - Andrei Apanasik


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'
like image 34
MikeM Avatar answered Nov 02 '22 23:11

MikeM


I think that JavaScript RegEx does not support this syntax.

May be this will help?

XRegExp

like image 22
jdb Avatar answered Nov 02 '22 23:11

jdb