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 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比