Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

GREP something close to negative lookahead?

New Here ,
Dec 16, 2021 Dec 16, 2021

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
798
Translate
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

Guide , Dec 17, 2021 Dec 17, 2021

… Supposing each line is a single para:

 

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

 

(^/)  The Jedi

Translate
Community Expert ,
Dec 17, 2021 Dec 17, 2021

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.

Translate
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
Community Expert ,
Dec 17, 2021 Dec 17, 2021

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.

 

Translate
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
Community Expert ,
Dec 17, 2021 Dec 17, 2021

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

Translate
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
Community Expert ,
Dec 18, 2021 Dec 18, 2021

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.

Translate
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
Guide ,
Dec 17, 2021 Dec 17, 2021

… Supposing each line is a single para:

 

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

 

(^/)  The Jedi

Translate
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

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

Translate
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
LATEST

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

Translate
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