在正则表达式中仅匹配字母的最佳方法是什么? [英] What is the best way to match only letters in a regex?

查看:122
本文介绍了在正则表达式中仅匹配字母的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很想使用\ w,但是它也与下划线匹配,所以我要使用[A-Za-z],它感觉到不必要的冗长和以美国为中心.有一个更好的方法吗?像[\ w ^ _]之类的东西(我怀疑语法是否正确)?

I would really like to use \w but it also matches underscores so I'm going with [A-Za-z] which feels unnecessarily verbose and America centric. Is there a better way to do this? Something like [\w^_] (I doubt I got that syntax right)?

推荐答案

您也可以使用/[a-z]/i/[[:alpha:]]/.实际上,\w包含数字,因此甚至无法使用.

You could use /[a-z]/i or /[[:alpha:]]/ just as well. In fact, \w includes numbers so that won't even work.

这篇关于在正则表达式中仅匹配字母的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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