Why does \w match only English words in javascript regex?

后端 未结 10 890
借酒劲吻你
借酒劲吻你 2020-12-09 20:26

I\'m trying to find URLs in some text, using javascript code. The problem is, the regular expression I\'m using uses \\w to match letters and digits inside the URL, but it d

10条回答
  •  暖寄归人
    2020-12-09 20:42

    I've just found XRegExp which has not been mentioned yet and I'm quite impressed with it. It is an alternative regular expression implementation, has a unicode plugin and is licensed under MIT license.

    According to the website, to match unicode chars, you'd use such code:

    var unicodeWord = XRegExp("^\\p{L}+$");
    
    unicodeWord.test("Русский"); // true
    unicodeWord.test("日本語"); // true
    unicodeWord.test("العربية"); // true
    

提交回复
热议问题