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

后端 未结 10 884
借酒劲吻你
借酒劲吻你 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:36

    Because \w only matches ASCII characters 48-57 ('0'-'9'), 67-90 ('A'-'Z') and 97-122 ('a'-'z'). Hebrew characters and other special foreign language characters (for example, umlaut-o or tilde-n) are outside of that range.

    Instead of matching foreign language characters (there are so many of them, in many different ASCII ranges), you might be better off looking for the characters that delineate your words - spaces, quotation marks, and other punctuation.

提交回复
热议问题