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:
main();
And change it to this:
var swatch = app.activeDocument.swatches.item("Black").duplicate();
swatch.name = "temp url";
main();
swatch.remove();
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.