We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

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


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.

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
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.



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)

with following lines of code.

	for (Run run : (Iterable<Run>) runs)

Hope this helps you.