#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    37
    Rep Power
    7

    Help on explain a preg_match


    Hello, All,

    I am new to regular expression.
    Could somebody help me to explain what the following preg_match is trying to match?

    preg_match_all( '/.{1,99}( |\Z)/i', $line, $matches );

    Thank you very much for your help.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,113
    Rep Power
    9398
    .{1,99} looks for 1-99 characters (because "." matches almost anything).
    ( |\Z) is either a space (I assume that's a space in there) or a \Z, which marks an optional newline followed by the end of the string.

    So in English, $line must contain 1-99 characters followed by either a space or the end of the string (maybe with a newline just before).
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    37
    Rep Power
    7
    Thank you very much. Now I got it!

    Originally Posted by requinix
    .{1,99} looks for 1-99 characters (because "." matches almost anything).
    ( |\Z) is either a space (I assume that's a space in there) or a \Z, which marks an optional newline followed by the end of the string.

    So in English, $line must contain 1-99 characters followed by either a space or the end of the string (maybe with a newline just before).

IMN logo majestic logo threadwatch logo seochat tools logo