Is it possible to work with Russian characters, in javascript's regex?
Maybe the use of \p{Cyrillic}?
If yes, please provide a basic example of usage.
The example:
var str1 = "абв прв фву";
var regexp = new RegExp("[вф]\\b", "g");
alert(str1.replace(regexp, "X"));
I expect to get: абX прX
It should work if you just save the JavaScript file in UTF8. Then you should be able to enter any character in a string.
edit: Just made a quick example with some cryllic characters from Wikipedia:
var cryllic = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюяабвгдеёжзийклмнопрстуфхцчшщъыьэюя';
cryllic.match( 'л.+а' )[0];
// returns as expected: "лмнопрстуфхцчшщъыьэюяа"
Here is a good article on JavaScript regular expressions and unicode. Strings in JavaScript are 16 bit, so strings and RegExp objects can contain unicode characters, but most of the special characters like '\b', '\d', '\w' only support ascii. So your regular expression does not work as expected due to the use of '\b'. It seems you'll have to find a different way to detect word boundaries.
According to this:
JavaScript, which does not offer any Unicode support through its RegExp class, does support \uFFFF for matching a single Unicode code point as part of its string syntax.
so you can at least use code points, but seemingly nothing more (no classes).
Also check out this duplicate of your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With