正则表达式:必须以字母或数字开头,其余可以是任何内容 [英] Regex: must start with a letter or a number but the rest can be anything

查看:71
本文介绍了正则表达式:必须以字母或数字开头,其余可以是任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个模式以用于验证.

I am trying to construct a pattern in order to use in validation.

我的目标是让第一个字符是字母或数字,其余的都可以.

My goal is to have the first character to be a letter or a number, the rest anyhing.

例如:

  1. A'r4nd0m!
  2. 9!h3ll0.
  3. b1llin6s

我想到了:[a-zA-Z0-9_/][.*]++

解决方案是什么?

谢谢!

推荐答案

正如我所评论的,一个字母或一个数字是 [\pL\pN].因此,以其中之一开头的字符串将匹配模式

As I’ve commented, a letter or a number is [\pL\pN]. Therefore a string beginning with one of those would match the pattern

/^[\pL\pN]/

这篇关于正则表达式:必须以字母或数字开头,其余可以是任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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