Copy link to clipboard
Copied
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,}
1 Correct answer
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
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!

