Hi, I'm new to scripts.
Performing searches I can apply styles to specific words, so far so good, but the problem is that my document has many tables where that searched word is also present, is there a way to apply the style only in the document and not in the tables? Maybe using script?
I would appreciate your help. And sorry for my writing, I don't speak English well.
I am attaching a picture so you can better understand what I want.
Copy link to clipboard
the basic algorithm could be this:
 Run a GREP Find action and store the found texts to an array.
 Loop that array of results and check the parent of the found text snippets.
If the parent is a cell, do nothing and continue to the next found item.
If the parent is not a cell do a change to that found text.
Look up this discussion we recently had:
[JS] Problem with change grep with look behind/ahead and /K
Kasyan Servetsky, Mar 16, 2022
In a nutshell the code below should work for you with GREP Find/Change. Not intensively tested, though. That's your job. To make that work do the following:
 Do your settings in InDesign's GREP Find/Change normal user interface.
If the result is not to your liking you can undo the whole thing with one single undo that is reading:
"Find/Replace GREP; Leave out Tables | SCRIPT"
Thanks Kasyan Servetsky for providing the core part of the code.
( ACP )
Note: EDITED my post above, because I did some comments to the code.
( ACP )
Thank you very much Laubender the code worked perfectly, I appreciate it very much, I will review the link you gave me to learn much more.
Greetings from Bolivia