Copy link to clipboard
Copied
Hey all, I'm trying to eliminate many lines of text in InDesign. The only lines of text I want to keep are those that contain certain keywords.
The block of text changes every time we use it, and it may or may not contain one or more instances of any of the keywords. It also will contain occasional special characters and definitely will have digits and spaces.
Here's an example of a text block we might receive:
Basketball
Boys
Wednesday’s results
Nonsection
Team 65, Team Teamy 53
St. Teamy 55, Team 52
Thursday’s schedule
Nonsection
TeamA at Team Beee, 7:30 p.m.
Team-Teamy at St. Teamer's, noon
From that example, we might want to kill every line that does NOT contain "St. Teamy" or "Team Beee".
Is this possible? I'm no pro GREP-er, but I haven't found a solution yet. I want to run this GREP query through InDesign, and I'm OK with multiple queries if necessary. Thank you for your time!
… Supposing each line is a single para:
^(?!.*\b(St.\hTeamy|Team\hBeee)\b).*$\r?
(^/) The Jedi
Copy link to clipboard
Copied
Are these all one paragraph, or is each line a separate paragraph? Unless each line is it's own paragraph I don't think you have a prayer of getting a GREP solution. though it's probably scriptable.
Copy link to clipboard
Copied
You could do it as follows:
1. Add some format to all lines that contain your keyword(s), e.g. underline.
2. Delete everything that's not underlined.
3. Remove the undrline codes.
Copy link to clipboard
Copied
But how do you identify single lines if they are part of a larger paragraph?
Copy link to clipboard
Copied
If they are part of a multi-line paragraph you're not going to find then with a single GREP expression, you'd need a script for that. That goes for both mine and Michel's (much better) solution. In Michel's expression, change the final \r? to [\r\n]? to get it to work in single paragraphs with forced line breaks.
Copy link to clipboard
Copied
… Supposing each line is a single para:
^(?!.*\b(St.\hTeamy|Team\hBeee)\b).*$\r?
(^/) The Jedi
Copy link to clipboard
Copied
Many thanks for the quick responses! And, to answer: every line is indeed its own paragraph. I'll report back after I do some testing. Thanks again...
Copy link to clipboard
Copied
Yep, seems to work like a charm. Thanks again to the community here, much appreciated!