Loading ...
Sorry, an error occurred while loading the content.

Re: [NTB] Re: Remove x number of characters from a line of text

Expand Messages
  • Alec Burgess
    Its actually pretty easy. ^!replace (?-s).*?-[2-9].*?( R| Z) rwsai or if using Find / Replace dialog: Find=(?-s).*?-[2-9].*?( R| Z) Replace=
    Message 1 of 22 , May 29, 2012
    • 0 Attachment
      Its actually pretty easy.

      ^!replace "(?-s).*?-[2-9].*?(\R|\Z)" >> "" rwsai
      or if using Find / Replace dialog:
      Find=(?-s).*?-[2-9].*?(\R|\Z) Replace=<empty>

      This will match entire lines which contain -[2-9] including ending
      new-line and replace the entire thing with nothing.

      Note: (?-s) (means . does not match new line characters is not strictly
      speaking necessary (its the default and besides we are ending or match
      with a new line. I like to include it just to make it explicit.

      The (\R|\Z) says match new-line or end of buffer. W/O the |\Z a match in
      the last line would not get deleted if there was not an empty line at EOF.

      btw: If testing in RegexBuddy be aware that it supports an earlier
      version of PCRE and hence does NOT support \R and \K.
      Use \r\n instead of \R (which matches any kind of line-ending. Windows
      uses \r\n but you may run into files created in Unix or Mac - one uses
      singleton \r, the other singleton \n; I forget which is which)

      I leave finding out what the very useful \K does an "exercise for the
      reader" :-X

      Regards ... Alec (buralex@gmail& WinLiveMess - alec.m.burgess@skype)


      On 2012-05-28 20:59, biwilliams wrote:
      > OK, I am learning (slowly).... starting to use some regexes after some
      > trial and error.
      > But I now have a new need which I have yet to master.
      > Hoping you guys can help....
      > Let's say I have repetitive lines in my data.
      > I have a used the expression -[2-9].* to remove all data from a line
      > whenever a digit between 2 and 9 follows a hyphen.
      > This has worked beautifully to help me visually see those lines within
      > the whole set.
      > But what I really want is to be able to delete those lines completely
      > from the data set.
      > Is there a way, either prior to, or after using the aforementioned
      > regexp, to delete the line in its entirety?
      > If this helps, after running that expression, the lines of data to be
      > deleted are now only 8 characters in length. Is there a way to say "if
      > a line only contains 8 characters (including whitespaces), delete that
      > whole line"?
    Your message has been successfully submitted and would be delivered to recipients shortly.