I use a complex .txt for the basic findchangebylist-script that is included in inDesign to fix some common typography mistakes. F.e. it changes the hyphen to an en dash and puts a thinspace between 3-4 or puts a fixed space between p.4 (page four). Sadly this destroys URLs if they contain these. For exhample http://www.file3-4p.4fire.com becomes http://www.file3 - 4p. 4fire.com.

Is there anyway to exclude anything that is preceded by http? As I understand, there is no negative lookbehind with variable length like it exists for the positive lookbehind with \K. But does anyone know a workaround for this?

My grep for these exhamples is like this:

grep    {findWhat:"([0-9]\\.?)\\s?[~=-]\\s?([0-9])"}    {changeTo:"$1~|~=~|$2"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} 
grep    {findWhat:"(p\\.)\\s?([0-9])"}  {changeTo:"$1~s$2"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} 
  • I think that's doable but I would also find a way to define the end boundary (.com ). Are all of your URLs ending with .com or a break of some sort?
    – curious
    Jun 15, 2021 at 11:21
  • No, they are always ending with some variable. They are mostly (but not always) dois like this doi.org/10.1037/0003-066X.55.11.1196 . Sometimes they end with a number, sometimes with a letter or other character.
    – SabineR
    Jun 15, 2021 at 11:40

1 Answer 1


Assuming all your text is black, you could first apply some other color to URLs, then perform the GREP find/change to all black text and finally change the color of URLs back to black.

Create a color swatch which you only use for temporarily coloring the URLs. Here I call it temp url.

First we select URLs with http(s)?://[^\s\r]+(?=\s|\r|). This should work with URLs followed by a white space or a paragraph break or positioned at the end of a story. You can tweak this to fit your needs. In the changeProperties object we set fillColor to the name of the temporary swatch for URLs: temp url.

grep    {findWhat:"http(s)?://[^\\s\\r]+(?=\\s|\\r|)"}  {fillColor:"temp url"}  {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

Then follows whatever changes you want to make. In the findProperties object of each search we set fillColor to Black to only apply changes to black text.

grep    {findWhat:"([0-9]\\.?)\\s?[~=-]\\s?([0-9])", fillColor:"Black"} {changeTo:"$1~|~=~|$2"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} 
grep    {findWhat:"(p\\.)\\s?([0-9])", fillColor:"Black"}   {changeTo:"$1~s$2"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

Finally we change the color of URLs back. In the findProperties object we set fillColor to temp url and in the changeProperties we set fillColor to Black.

grep    {fillColor:"temp url"}  {fillColor:"Black"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

Further automatization

Instead of manually adding the temporary swatch for the URLs, it's possible to add it within the FindChangeByList.jsx script. I would copy the script and the FindChangeSupport folder to the folder with user scripts first though.

Locate the line in the beginning of the script that looks like this:


And change it to this:

var swatch = app.activeDocument.swatches.item("Black").duplicate();
swatch.name = "temp url";

This will make a duplicate of the Black swatch, name it temp url, run the main function and in the end remove the temp url swatch again.

  • That sounds promising but apart from some minor differences which I might be able to solve, i can't seem the grab the standard [black] (which is [schwarz] in my indesign). It works with any other new color but not with the standard one. Is there a way to grap that? Is it also possible to create the temp url color via the txt or maybe by editing the jsx?
    – SabineR
    Jun 16, 2021 at 10:50
  • I was fearing you might get trouble with that 😀. And you have of course tried both "schwarz" and "Schwarz"? But yes, you could do it within the jsx and thereby eliminating the need for the custom swatch I think. It's just way more complicated to explain. But that wouldn't solve the problem with not being able to search only within [Black] text, would it? You have to find out how to select it in the German version.
    – Wolff
    Jun 16, 2021 at 12:38
  • I managed it to work, for some reason I wrote "Black" in small letters so that was the problem. Thank you. I put in everything you wrote and it works wonderfully. (I used (http(s)?://[^ ]+(?=\r))|(http(s)?://[^ ]+(?= )) to include the URLs at the end of a paragraph.) Now I need to find a way to create this temporary color without needing to resort to do it manually.
    – SabineR
    Jun 16, 2021 at 13:13
  • Ah, you can create the swatch in the .jsx file with some name, then refer to that name in the .txt and afterwards delete it again. I might add this to the answer later.
    – Wolff
    Jun 16, 2021 at 13:24
  • Thanks, I'm still trying to figure out how. I managed to add a color but still need to figure out how to not make it fail if the color name already exists (if the script is used a second time it fails.) Sadly my scripting knowledge ist barely existend. What does work for me though, is to use an existing color we already have in our templates and use the GREP for the URL again to switch it to black again. But I still want to find out how to do it your way.
    – SabineR
    Jun 16, 2021 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.