0

I'm in a sticky situation with a CSV file. I have many rows of text with CRLF throughout which is ruining the formatting when I put it in Excel. I need to be able to remove the CRLF only when not preceded by a tab delimiter.

I plan on doing this with a regular expression in find and replace (but open to other ideas) I've read that it is possible to have if statements in regex and wondered if it's possible to highlight for removal based upon the outcome of the if?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Intern87
  • 469
  • 1
  • 6
  • 18

1 Answers1

1

i think regular expression matching what you want is [^\t]\r\n

you can use a text editor that support regular expression to do the search and replace, in vim it can be something like

%s/\t\@!\r\n/<your_replacement>/g

note that \@! is the vim way of not, in other solutions this can be different

miushock
  • 1,087
  • 7
  • 19
  • Thank you for answering my question. I am using TextPad on windows. I think I need to split your expression into two pieces for the find/replace function.find: %s/\t\@!\r\n/ & replace: /g But it says it cannot find regex %s/\t\@!\r\n/ – Intern87 Mar 21 '14 at 01:01
  • %s is a vim command for search and replace, it's not part of regular expression, you might want to try [^\t]\r\n if you are using textpad? – miushock Mar 21 '14 at 01:05
  • fantastic, it's finding them now but eh replacement is also removing the last two characters on the line...any thoughts? – Intern87 Mar 21 '14 at 01:11
  • The problem is the 'not tab' character also get included in pattern and got replaced. The 'search but not include' functionality is not part of standard regex, but there is implementation on it. You might want to check http://stackoverflow.com/questions/3850074/regex-until-but-not-including for detailed explaination – miushock Mar 21 '14 at 01:18