例如:
    $str = "h2222222222\n";
  $preg ="/^h\d+$/is";
  preg_match($preg,$str,$arr);
为什么能匹配成功,\n应该才是最后一个字符吧??

解决方案 »

  1.   

    D (PCRE_DOLLAR_ENDONLY)
    If this modifier is set, a dollar metacharacter in the pattern matches only at the end of the subject string. Without this modifier, a dollar also matches immediately before the final character if it is a newline (but not before any other newlines). This modifier is ignored if m modifier is set. There is no equivalent to this modifier in Perl."$" 默认是匹配换行符的.<?php
    $str = "h2222222222\n";
    $preg ="/^h\d+$/isD";
    preg_match($preg,$str,$arr);
    var_dump($arr);