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

23908Re: [Clip] Re: Need help with RegExp to delete columns

Expand Messages
  • Art Kocsis
    Jul 14, 2013
      At 7/13/2013 01:39 PM, Joy wrote:
      >--- In <mailto:ntb-clips%40yahoogroups.com>ntb-clips@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
      >> --- In <mailto:ntb-clips%40yahoogroups.com>ntb-clips@yahoogroups.com, "joy8388608" <mycroftj@> wrote:
      >> >
      >> > I wanted to create a clip that would allow me to delete a
      >> > specified column (...)
      >> ^!Set %R%=^?{Remove column:==First^=F|Second^=1|Third^=2}
      >> ^!IfSame "^%R%" "F" Next Else Skip_2
      >> ^!Replace "^([^,\r\n]+|,),{0,1}" >> "" WARS
      >> ^!Goto End
      >> ^!Replace "^([^,\r\n]{0,},){^%R%}\K\w{0,}," >> "" WARS
      >> Regards,
      >> Flo
      >Flo and Art -
      >Thanks very much for the help. (Sorry for the delay - I didn't want to reply until I had time to test)
      >For others taking notes, I made a few changes since there were two small problems which I think I fixed and I also replaced the \w since there could be other characters involved.
      >I really appreciate the help. I am not helpless when pointed way down the correct path, but I could never have gotten here without help. Never was very successful with recursion either...
      >Problems fixed:
      >Remove column 1 was turning ",,33" to "33" instead of ",33" and remove column x was not working if there were exactly x columns
      >^!Set %R%=^?{Remove column:==First^=F|Second^=1|Third^=2}
      >^!IfSame "^%R%" "F" Next Else Skip_2
      >;^!Replace "^([^,\r\n]+|,),{0,1}" >> "" WARS
      >^!Replace "^([^,\r\n]*),{0,1}" >> "" WARS
      >^!Goto End
      >;^!Replace "^([^,\r\n]{0,},){^%R%}\K\w{0,}," >> "" WARS
      >^!Replace "^([^,\r\n]{0,},){^%R%}\K[^,\r\n]{0,},{0,1}" >> "" WARS

      Here you go. This works for all column numbers, even negative ones. No changes are made for negative numbers or for any lines with fewer columns than the one to be deleted.

      My earlier suggestion worked fine for column selections one thru four but failed on your test data for higher values. Since your clip only covers columns one thru three that implies it would have been sufficient for you. Anyway, this removes any restriction on column numbers.


      ;<<<<<<<<<<<<<<<< Start of clip >>>>>>>>>>>>>>>>>>>>>>>>>
      ^!Set %K%=^?{Enter column # to delete}
      ^!Dec %K%
      ^!Replace "^([^\,\r\n]*,){^%K%}\K[^,\r\n]*(?|(,)([^\r\n]*?)|(\h*)())(?=\R|\Z)" >> "$3" AIRW

      ;Prev Rplc: ^!Replace "^([^\,]*,){^%K%}\K[^,]*,(.*(\R|\Z))" >> "$2" AIRW
      ;<<<<<<<<<<<<<<<< End of clip >>>>>>>>>>>>>>>>>>>>>>>>>
    • Show all 6 messages in this topic