^p vs. [^p] in Unix file using UE regex

^p vs. [^p] in Unix file using UE regex

35
Basic UserBasic User
35

    Jun 19, 2012#1

    According to documentation I have read, ^p is UE regex I can use in place of ^r^n

    I have UNIX PHP files (i.e. lines are terminated with \n). I just realized that a find operation for ^p results in nothing found, whereas a UE regex find for [^p] finds all the \n characters.

    Is this by design? Am I missing something?

    6,686585
    Grand MasterGrand Master
    6,686585

      Jun 19, 2012#2

      Well, ^p matches only DOS line terminators - carriage return + line-feed. ^p is short for ^r^n. That explains also why [^p] finds also Unix line terminators as this is resolved internally to [^r^n] and means now either carriage return or line-feed. Better would be [^p]+ as this results internally in [^r^n]+ and therefore matches now also DOS line terminators completely and not just the carriage return of a CR+LF pair. But care must be taken as [^p]+ matches now also multiple line terminators of any type.

      ^n should be used for UNIX line terminators as this special character matches only the line-feed.

      The internal replacement of [^p] by [^r^n] explains also why ^p used in a function string regular expression in a wordfile results in working for DOS, UNIX and MAC files taking into account that ususally after ] there is either + or * too.

      35
      Basic UserBasic User
      35

        Jun 19, 2012#3

        Thanks - now I get it.