9 Replies Latest reply on Nov 4, 2016 6:28 AM by Peter Spier

    Grep expression to include carriage return if it's there

    JustyR Level 1

      Hi all,

       

      Is there a grep expression that is able to handle a break return or other non-text character that might or might not be between a pair of tabs?

       

      I'm using Grep within BBEdit to convert Excel data into tagged XML, to then import into InDesign. However, when someone has put a carriage return within a cell in Excel, my find/replace won't handle that properly. I can use a workaround, but I didn't want to amend the original data if possible.

       

      My expression looks for 7 columns of text, and takes each piece and puts tags around them.

       

      filename    |    full name    |    star    |    company    |    biog    |    city    |    twitter

       

      johnsmith.tif    |    John Smith    |    yes    |    DeLoitte    |    I work at Deloitte and I'm brilliant.    |    New York    |    @myhandle

       

      Find:

      ^(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)$

       

      Replace:

      <person>

      <picbox href="file://Headshots/\1" />

      <name>\2</name>

      <star>\3</star>

      <company>\4</company>

      <biog>\5</biog>

      <city>\6</city>

      <twitter>\7</twitter>

      </person>

       

      But what if one of those columns has a break return but all the others don't? - Just to be clear, it MIGHT have a carriage return, it MIGHT NOT - this is the tricky bit.

       

      Is there a grep expression that can account for that?

       

      johnsmith.tif    |    John Smith    |    yes    |    DeLoitte    |    I work at Deloitte

      and I'm brilliant.    |    New York    |    @myhandle

       

      If anyone can help, that would be amazing.

       

      Thanks,

       

      Justy