Find hyperlink destination (URL) or anchor name from text source
Hi all,
First at all, as this is my very first message on this forum, but not the first time that I take advantage of your discussions, I would like to thank you all for your help, even if you don't know that you helped me! I discovered scripting a few years ago, and managed to develop some useful scripts for me and my team (I work for the French National History Museum journals), and I often found some solutions on this forum, and elsewhere too. So thank you all again.
Now this is my problem (I did not find any online solution for it on this forum or elsewhere, but perhaps I did not find the right words to search...):
I have an article prepared in Indesign, and in this article there are two kinds of links applied on the text: 1°/ links to external URL (e.g., https://science.mnhn.fr); and 2°/ links to internal anchors (for bibliography and figures, tables, etc.).
I would like to be able, with a script that uses a GREP expression to find some text, e.g. a specimen number like P01964577...

...to get the URL that corresponds to the link applied to this text.
I would also be able to "read" the name of the anchor, in case of a link to an internal target:

Nguyễn Kim Đào 2003 (just above) is linked in the article to an anchor (his name: "Nguyễn Kim Đào 2003") that has been placed at the beginning of the corresponding entry, in the bibliography:

In the same way as previously, I would like to be able, with a script that "reads" the text, to get the anchor name designated by the link on the text of the article.
So, to resume:
I have a grep script that searches a GREP expression, like "P\\d+"; it fills a table variable "res" that contains the result of the search, as objects.
res[0].contents.toString()
would send me (for example) "P00745313"
How do I get the URL (or the anchor name) that is placed on res[0]?
I precise that I visited (many times, it is dark-purple on my browser now) this thread: https://community.adobe.com/t5/indesign-discussions/find-hyperlink-text-source-from-destination/td-p/4405028
and what I would like is exactly the opposite!
I hope I have been clear enough in my explanations, please do not hesitate to ask me some precisions if needed, and thank you in advance for your answers, that will be useful for me in all cases!
Emmanuel
