Copy link to clipboard
Copied
Hi all -
I have a set of text in Indesign that I want to use a find and replace function. Let us this random Wikipedia article as an example:
Prior to the show, Jaymes gained popularity as an actor on Santa Barbara and also as a stand up comedian, including on the Fox network on the critically acclaimed The Sunday Comics.
I also have a set of characters that I would like to highlight in red (whatever to distinguish them from the rest of the text):
P s J y a S x C a T S C
I would be able to do this manually but in reality I have thousands of these characters to find in a large text file of over 100,000 digits (its will be very laborious). I also only want to highlight these in consecutive order through the text, so first P, and then the first s after P, and the first J after s and so forth. I do not want to highlight ALL the P's or ALL the S's etc.
If there a formula to do this in Find and Replace with TEXT or GREPS?
Many thanks for your support.
Copy link to clipboard
Copied
The first part is easy. Copy the text you want to replace and paste it into the Find what: field of InDesign's Find/Change dialog. Type or paste the replacement for the Find text into the Change to: field. Click Find Next and replace accordingly. If you're confident of what you're doing you can save time by clicking Change All.
If I understand you correctly, you want to find this string: P s J y a S x C a T S C and change it to red? Right? If so, see my screen shot. You could also create a GREP Style to apply Red to this string automatically.
Copy link to clipboard
Copied
Thanks Scott for your help here.
Im probably not being that precise (do excuse me):
I dont want to find these characters as a defined string one next to each other 'P s J y a S x C', I want to locate them within the text as they are found without inputting them all in individually. If I search for 'P s J y a S x C' nothing would come up as they are not to be found next to each other in the text.
I have added the letters in Bold where they first show up in the text below:
Prior to the show, Jaymes gained popularity as an actor on Santa Barbara and also as a stand up comedian, including on the Fox network on the critically acclaimed The Sunday Comics.
I want to see if I can find out a way that I can input this text 'P s J y a S x C' into a Find function and then let the programme locate the first instance of each letter and then following on from that convert it to red/italics/bold (anything to differentiate it to other).
Its probably easier to explain using words:
I do like dogs, but not as much as cats, dogs are definitely my favourite animal over cats.
'DOGS CATS'
I do not want to make red every dogs or cats just the first instance of them in the text.
Does this make more sense?
Copy link to clipboard
Copied
Well for starters, you could simply put a pipe symbol (|) between each letter in the Find what field in the GREP section of the Find/Change dialog box and then in the change format section choose the formatting you want to apply. The pipe symbol is the "or" operator and will find any of the letters on their own. In the screen shot below I'm using a red character style. That will find any instance of each letter in the text. Now if you can narrow down more specifics of when and where the letter will occur, we may be able to assist you further.

Copy link to clipboard
Copied
beg87656411 wrote
I do not want to make red every dogs or cats just the first instance of them in the text.
I'm not aware of the method to implement your full set of chars in a single search, however, that's not a big deal to make this using separate queries, like these:
^[^P]*\KP
^[^s]*\Ks
^[^J]*\KJ
^[^y]*\Ky
^[^a]*\Ka
^[^S]*\KS
^[^x]*\Kx
^[^C]*\KC
… and so on.
I think, the optimal approach would be to integrate these as a GREP styles to Paragraph style, and all you need to do then - just apply your 'magic' Parastyle to text. Notice it's easy to point to different formatting for each letter, if this is of any use.
Sure, it also can be used one-by-one in F/C dialog.
Copy link to clipboard
Copied
If the list gets too long it is possible to string together any number of greps via scripting.
Here's an Applescript (OSX only) example where the first line saves the string of characters to search for (no spaces between), and the second line is the name of the character style to apply—edit as needed:
set characterlist to every character in "PsJyaSxC"
set cstyle to "Bold Red"
tell application "Adobe InDesign CC 2018"
set c to every character style of active document whose name is cstyle
repeat with a in characterlist
my GrepSearch("^[^" & a & "]*\\K" & a, item 1 of c)
end repeat
end tell
on GrepSearch(f, c)
tell application "Adobe InDesign CC 2018"
set find grep preferences to nothing
set change grep preferences to nothing
set find what of find grep preferences to f
set applied character style of change grep preferences to c
change grep
end tell
end GrepSearch

Copy link to clipboard
Copied
Thanks so much rob day for this - I will attempt this later this week and may reply back if I have any questions!
Cheers
Copy link to clipboard
Copied
beg87656411 wrote
Its probably easier to explain using words:
I do like dogs, but not as much as cats, dogs are definitely my favourite animal over cats.
'DOGS CATS'
Also, it doesn't sound like you need to find and change a list of words, but the code for that would be different. I can post an example if you need that.
Copy link to clipboard
Copied
Sure, a set of F/C queries can be implemented in JS as well, thus effectively doing this task 'one-click'. However, it seems like a one-time job to me, and usually it's not worthwhile to bother compiling a special script. Also mind alternatives in-between, like ChainGREP or other similar pre-made scripts to manage multiple GREP queries. Whatever floats your boat…
I'd be much more interested in a single AIO regex, but that's hardly possible ![]()
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more