dongxiaoyan4388 2011-06-07 05:44
浏览 145
已采纳

$和*在PCRE(正则表达式)中意味着什么?

i am using a Regular Expression that validates an email address here is the regular expression i am using.

preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email)

most of the above code are self explanatory like

a) ^ represents NOT.

b) the start of the string should be either _ a-z 0-9

c) match the next character which starts with dot

d) now what does *@ means here, couldn't it be just @ which means the next character should be @

e) next again it will try and find dot, the first dot is optional and the second is compulsory.

f) in the end what does $ means?

  • 写回答

4条回答 默认 最新

  • duanmao1975 2011-06-07 05:49
    关注

    Your assumption a) is not true

    ^ is the start of the string in this case. At the beginning of a character class its a NOT.

    [_a-z0-9-]+ will match any of the chars in [] one or more times (because of the +)

    (\.[_a-z0-9-]+)* then there is a dot the same pattern than before and the * means this complete part can be repeated 0 or more times

    Then there has to be the character @

    Then the part from before the @ repeats

    (\.[a-z]{2,3})$ the string has to end (defined by the $) with a . and 2 or 3 lowercase letters

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

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭