In InDesign's GREP search I'm trying to get parts of a text field which was filled with a CSV (file using #
as delimiter). The reason I want to grep the different parts is to give each a different character style.
The Textfield content looks like this:
Alpha#60x50cm#Acryl
Beta#2013#50x40cm#Öl
Gamma#2013#50x40cm#Holz
…
Using
^[^#]+
would work fine to get the first part of each line, (which is delimited by the first hashtag)
How would Grep pattern look like to get:
In every line.
In the InDesign UI, you can
^[^#]+
to match the contents of the first field;(?<=#)[^#]+(?=#[^#]*#[^#]*$)
to match the contents of the second field;(?<=#)[^#]+(?=#[^#]+$)
to match the contents of the third field;(?<=#)[^#]+$
to match the contents of the fourth field.This relies on all lines having exactly four fields (and thus 3 #
), and will match only the text in between two #
markers. Here is an image showing the result with these four applied as GREP styles:
As you can see, the applied attributes overlap nowhere, so everything is only marked once.
Another way is to use Javascript. All of the lines can be split on the #
character (the command is called split
), and that returns an array of the text in between. However, this converts the text into a plain Javascript string, and it takes some trickery to translate the result "back" to native formatted text.