为什么\w只匹配javascript正则表达式中的英文单词? [英] Why does \w match only English words in javascript regex?

查看:664
本文介绍了为什么\w只匹配javascript正则表达式中的英文单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用javascript代码在某些文本中查找网址。问题是,我使用的正则表达式使用\w来匹配URL中的字母和数字,但它与非英语字符(在我的情况下是希伯来字母)不匹配。

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 doesn't match non-english characters (in my case - Hebrew letters).

那么我可以使用什么代替\ w来匹配所有语言中的所有字母?

So what can I use instead of \w to match all letters in all languages?

推荐答案

因为 \w 只匹配ASCII字符48-57('0' - '9'),67-90('A' - 'Z')和97-122('a' - 'z')。希伯来字符和其他特殊外语字符(例如,umlaut-o或tilde-n)超出该范围。

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.

而不是匹配外语字符(有如此多,在许多不同的ASCII范围内),你可能最好还是寻找描绘你的单词的字符 - 空格,引号和其他标点符号。

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.

这篇关于为什么\w只匹配javascript正则表达式中的英文单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆