正则表达式匹配数字和字符 [英] regular expression match digit and characters

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

问题描述

如何创建仅匹配字符和数字的正则表达式?

How can I create a regex expression that will match only characters and numbers?

此正则表达式匹配的宽度数字:/\ D/g

this regex matched width digit: /\D/g

如何在其中添加- _ * 等字符?

how can add characters like - , _ , * and etc to it?

推荐答案

仅匹配字母和数字,

[A-Za-z0-9]

将想要的字符添加到上述字符类中,以匹配特定字符.

Add the characters you want into the above character class to match also that specific characters.

[A-Za-z0-9_*-]

您可以将上述正则表达式减少为

You could reduce the above regex to,

[\w*-]

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

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