正则表达式匹配非英文字符? [英] Regular expression to match non-English characters?

查看:2233
本文介绍了正则表达式匹配非英文字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在正则表达式中匹配非英文字符的最简单方法是什么?我想在输入字符串中单独匹配所有单词,但语言可能不是英语,所以我需要匹配ü,ö,ß和ñ等内容。此外,这是在Javascript / jQuery中,因此任何解决方案都需要应用于此。

What is the easiest way to match non-English characters in a regex? I would like to match all words individually in an input string, but the language may not be English, so I will need to match things like ü, ö, ß, and ñ. Also, this is in Javascript/jQuery, so any solution will need to apply to that.

推荐答案

这应该这样做:

[^\x00-\x7F]+

它匹配任何字符未包含在 ASCII字符集(0-127,即0x0至0x7F)中。

It matches any character which is not contained in the ASCII character set (0-127, i.e. 0x0 to 0x7F).

你可以用Unicode做同样的事情:

You can do the same thing with Unicode:

[^\u0000-\u007F]+

对于unicode,你可以看看这两个资源:

For unicode you can look at this 2 resources:

  • Code charts list of Unicode ranges
  • This tool to create a regex filtered by Unicode block.

这篇关于正则表达式匹配非英文字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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