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

GREP for multiple spaces NOT preceded by two particular words

Engaged ,
Jul 29, 2019 Jul 29, 2019

I'm trying to GREP for multiple spaces, but some copyright notices that appear frequently contain multiple spaces that I am not allowed to remove, and throw up many, many false positives. However, the "legal" multiple spaces are always preceded by one of a few words "Secured", "Copyright" or "Reserved".

Is there any way to match multiple spaces that are NOT preceded by these words.

I tried things like this but I think I've got the wrong approach. Maybe this isn't possible, it 'feels' like there should be a way to do it, but I could wrong!

(?<!Secured|Copyright) {2,}

552
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

Community Expert , Jul 30, 2019 Jul 30, 2019

The lookbehind in InDesign has a limit: you cannot search for items with a variable length. In the expression "any of these words (Secured|Copyright|Reserved)", all of the words have a different length, so the 'result' of the lookbehind would be variable as well.

To get around it, create a separate lookbehind for each word:

(?<!Secured)(?<!Copyright)(?<!Reserved)\s{2,}

However, there may be a simpler solution. Having more than a single plain space anywhere is sort of a no-no. InDesign has lots of s

...
Translate
Community Expert ,
Jul 30, 2019 Jul 30, 2019

The lookbehind in InDesign has a limit: you cannot search for items with a variable length. In the expression "any of these words (Secured|Copyright|Reserved)", all of the words have a different length, so the 'result' of the lookbehind would be variable as well.

To get around it, create a separate lookbehind for each word:

(?<!Secured)(?<!Copyright)(?<!Reserved)\s{2,}

However, there may be a simpler solution. Having more than a single plain space anywhere is sort of a no-no. InDesign has lots of spaces with a fixed width; in your case, I'd probably search and replace the two spaces following these words with a single en-space – if that is not enough, try an em-space.

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
Engaged ,
Jul 30, 2019 Jul 30, 2019
LATEST

Thanks so much. I had no idea about the use of multiple match clauses   This enabled me to construct exactly what I needed.

I couldn't use \s as it lead to it finding multiple uses of \r which was not desired. Weird how those count as "whitespace" although I can kind of understand why.

I also ran into an issue where if there were three spaces after "Copyright" it would select spaces 2 & 3 but not 1 thereby shortcutting the lookbehind rule, so I also added (?<! ) which made it look more complex again but at least worked.

The workaround tip is also handy one that hand not occurred to me while battling with the GREP!

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