dsdf64562672 2011-03-08 15:59 采纳率: 0%
浏览 85
已采纳

带有下划线正则表达式的字母数字

I'm extending the CodeIgniter Form Validation library to check for Alpha Numeric values with underscores excluding dashes. But I'm very new to regex patterns and would like some help...

Currently for alpha_numeric CI has:

return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE;

And for alpha_dash CI has:

return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE;

And I'm creating 'alpha_underscore' (which again will be alpha numeric with underscores):

Is this correct?

return ( ! preg_match("/^([a-z0-9_])+$/i", $str)) ? FALSE : TRUE;

I am confused as to why there is a '-' at the beginning and end of the 'alpha_dash' pattern

  • 写回答

2条回答 默认 最新

  • dt2015 2011-03-08 16:06
    关注

    The character class [-a-z0-9_-] is same as [a-z0-9_-] or [-a-z0-9_].

    One of the - can be dropped.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用