regex multiline modifier and windows line endings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Allen

    regex multiline modifier and windows line endings


    In regex, ^ and $ shoudl match start/end of a line when the 'm' /multiline
    modifier is set -- however I just spent the better part of the day trying
    to figure out why it wasn't working as expected. I used the query
    test$
    ....and the text
    test
    test
    test

    Only the last instance of test would match -- that is expected without the
    multiline flag. ( http://tinyurl.com/dx86w ) however they should each
    match with the multiline flag so long as there's no additional whitespace
    after the fact ( http://tinyurl.com/7bap6 ).

    Finally, out of ideas, I replaced \r\n with \n on all of my _POST data --
    and presto, it worked. So, my question is -- why won't it work on data
    with windows line endings? Is there a built in function for changing the
    line ending style or something? It seems there should be a more elegant
    solution than running a find/replace on all of my user-input just to make
    sure the line ending style are liked by PCRE.

    Thanks

    A.
  • Mladen Gogala

    #2
    Re: regex multiline modifier and windows line endings

    On Tue, 31 Jan 2006 15:41:47 -0500, Allen wrote:
    [color=blue]
    >
    > In regex, ^ and $ shoudl match start/end of a line when the 'm' /multiline
    > modifier is set -- however I just spent the better part of the day trying
    > to figure out why it wasn't working as expected. I used the query
    > test$
    > ...and the text
    > test
    > test
    > test
    >
    > Only the last instance of test would match -- that is expected without the
    > multiline flag. ( http://tinyurl.com/dx86w ) however they should each
    > match with the multiline flag so long as there's no additional whitespace
    > after the fact ( http://tinyurl.com/7bap6 ).
    >
    > Finally, out of ideas, I replaced \r\n with \n on all of my _POST data --
    > and presto, it worked. So, my question is -- why won't it work on data
    > with windows line endings? Is there a built in function for changing the
    > line ending style or something? It seems there should be a more elegant
    > solution than running a find/replace on all of my user-input just to make
    > sure the line ending style are liked by PCRE.
    >
    > Thanks
    >
    > A.[/color]


    Allen, I've never encountered such problem because I normally
    clean up all "\r" characters, whenever I encounter them,
    but there is a parameter "auto_detect_li ne_endings" in your php.ini
    which is normally set to "Off".

    --


    Comment

    • Allen

      #3
      Re: regex multiline modifier and windows line endings

      On Fri, 03 Feb 2006 07:40:04 -0500, Mladen Gogala <gogala@sbcglob al.net>
      wrote:
      [color=blue]
      > On Tue, 31 Jan 2006 15:41:47 -0500, Allen wrote:
      >
      >
      > Allen, I've never encountered such problem because I normally
      > clean up all "\r" characters, whenever I encounter them,
      > but there is a parameter "auto_detect_li ne_endings" in your php.ini
      > which is normally set to "Off".[/color]

      That'll probably do it. In my code, I never use \r -- the problem was
      from user-input, which hadn't occurred to me to manually clean up. Thanks
      much.

      Comment

      Working...