Find and replace text between << and >> using Java

Hi,

I need to get a text which is included inside a defined set of chars. So I thought to use doc.getRange().replace with regular expression to find all phrases matches the regular expression, but how can I get the text inside the regular expression? I can’t find an API to find a text, there’s only the replace one.

Example
I’ve a simple document word whit a phrase like this:
"This is a sample text <<[a.b.c.d.e]>> with a tag
And I need to get
"a.b.c.d.e"
In general, all tokens inside <<[…]>>

Using this code I can find how many tag <<[…]>> are in the document.
int replaced = doc.getRange().replace(Pattern.compile("(<<\\[)[a-zA-Z0-9._]+(\\]>>)"), "replace", new FindReplaceOptions(FindReplaceDirection.FORWARD));
but I can’t find and get a text inside a document.

Thanks

@voxopake

In your case, we suggest you please read the following article.
How to Find and Highlight Text

The code example shared in above article finds and highlights the text. You can replace following lines of code

	for (Run run : (Iterable<Run>) runs)
		run.getFont().setHighlightColor(Color.YELLOW);

with following lines of code.

	for (Run run : (Iterable<Run>) runs)
		System.out.println(run.getText());

Hope this helps you.