GREP something close to negative lookahead?

New Here ,
Dec 16, 2021 Dec 16, 2021

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!

TOPICS
Print

Views

172

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advisor , Dec 17, 2021 Dec 17, 2021

… Supposing each line is a single para:

 

^(?!.*\b(St.\hTeamy|Team\hBeee)\b).*$\r?

 

(^/)  The Jedi

Likes

Translate

Translate
Adobe Community Professional ,
Dec 17, 2021 Dec 17, 2021

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 17, 2021 Dec 17, 2021

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.

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 17, 2021 Dec 17, 2021

Copy link to clipboard

Copied

But how do you identify single lines if they are part of a larger paragraph?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 18, 2021 Dec 18, 2021

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 17, 2021 Dec 17, 2021

Copy link to clipboard

Copied

… Supposing each line is a single para:

 

^(?!.*\b(St.\hTeamy|Team\hBeee)\b).*$\r?

 

(^/)  The Jedi

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 18, 2021 Dec 18, 2021

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...

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 19, 2021 Dec 19, 2021

Copy link to clipboard

Copied

LATEST

Yep, seems to work like a charm. Thanks again to the community here, much appreciated!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines