正则表达式,如何允许点(句点)和字母组合? [英] Regular expression, How to allow combination of dot (period) and letters?

查看:45
本文介绍了正则表达式,如何允许点(句点)和字母组合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许 (.) 和 (a-zA-Z) 字母和 _ 和 - ,我对 (.) 有一些问题,

I want to allow (.) and (a-zA-Z) letters and _ and - , I have some problems with the (.) ,

有什么想法吗?

提前致谢,

伊什

推荐答案

[A-Za-z_.-]

是一个字符类,包含您提到的所有字符.在字符类中,没有必要对 . 进行转义,如果将 - 放在首位或最后,则可以避免对其进行转义.

is a character class that includes all the characters you mentioned. Inside a character class, it's not necessary to escape the ., and you can avoid escaping the - if you put it first or last.

如果数字也可以,您可以将其缩短为

If numbers are ok, too, you can shorten this to

[\w.-]

这篇关于正则表达式,如何允许点(句点)和字母组合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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