英文字符,连字符和下划线的正则表达式 [英] Regex for english characters, hyphen and underscore

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

问题描述

我需要使用正则表达式来输入英文字符,连字符和下划线

I need Regex for english characters, hyphen and underscore

示例

匹配:


govind-malviya
govind_malviya
govind123
govind

不匹配


govind malviya
govind.malviya
govind%malviya
腕錶生活
вкусно-же

推荐答案

尝试一下:

^[A-Za-z\d_-]+$

A-Za-z 将允许使用字母.
\ d 将允许数字.
_ 将允许使用下划线.
-将允许使用连字符. ^ $ 分别表示字符串的开头和结尾.

A-Za-z would allow alphabets.
\d would allow numbers.
_ would allow underscore.
- would allow hyphen. ^ and $ represent the start and end of string respectively.

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

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