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

47381RE: Removing blank lines from a string

Expand Messages
  • David Fishburn
    Feb 2, 2004
    • 0 Attachment
      > -----Original Message-----
      > From: Suresh Govindachar [mailto:sgovindachar@...]
      > I think the following is the solution:
      >
      > substitute(@a, '^\(\s*\n\)*\|\n\s*\n\@=', '', 'g')
      >
      > I have tested it with 0 or more blank lines at the beginning,
      > at the end and in between two non-trivial lines; blank lines
      > with and without white space; non-trivial lines starting and
      > ending with and without blank space.


      That is brilliant, thanks.

      I have run my own tests, and it does exactly what I need.

      I understand this part to get rid of empty lines at the start of the string.
      '^\(\s*\n\)*

      And this part to get blanks lines in the middle of the string:
      \n\s*\n

      But I don't understand this part to get rid of the empty lines up to the end
      of the string:
      \n\s*\n\@=

      Ahh, I think I understand. That matches the last \n with zero width, so it
      does not
      include it in the pattern. Therefore, a blank substitution can be used.

      Thanks!
      Dave
    • Show all 10 messages in this topic