Find text with Regex - Aspose Words for java

Hi,

I’m trying to find all text in a word document that matches this regex " ^{-(.*) " . For now I just want to print all matches to the console.

When testing online with a regex tester, my test case “{-test-}” works, but when I try to use it with replace() it doesnt seem to find a match. Any ideas why this isn’t working? I’ve attached the document and java project.

AsposeFindTextWithRegex.zip (12.1 KB)
RegexTest.zip (8.9 KB)

@austinmcnicholas

We have tested the scenario using the latest version of Aspose.Words for Java 19.6 and have not found the shared issue. So, please use Aspose.Words for Java 19.6.

I’ve updated my library to the latest version and still doesnt seem to work. Did you test using my project? Maybe I’m doing something wrong. I have a working find and replace implementation and when I use the regex with that it still doesn’t find a match. Do I have to specify if im using regex?

@austinmcnicholas

Following is the output that we get at our side using your code example.

Document received
{-(.*)
Attempting find and replace
Match found: {-Test-}
find and replace done

Could you please share your expected output? We will then provide you more information about your query.

Thats the output that Im trying to receive but when I run my code I get

Document received
{-(.*)
Attempting find and replace
find and replace done

@austinmcnicholas

Please use the latest version of Aspose.Words for Java 19.6 and let us know if you still face problem. Please also make sure that you are using the same document.

Hi Tahir,

I am using the latest version that you mentioned. Here is a screenshot

image.png (53.7 KB)

@austinmcnicholas

You are using Aspose.Words without license. Please get the 30 days temporary license and apply it before importing the document into Aspose.Words’ DOM.

Hi Tahir,

That solved the issue. But now I’m seeing that its only finding one match and then stopping. If I add any other words that would match it will only print one match to the console. Should I not be using the Replace action skip?

@austinmcnicholas

We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-18719. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

We suggest you please use Range.Replace Method (String, String, FindReplaceOptions) method instead of Range.Replace Method (Regex, String, FindReplaceOptions). Please check the following line of code.

int replace = doc.getRange().replace("{-", "", findReplaceOptions

Ok thanks. How long do issues usually take to get fixed?

Also I submitted a different topic because I wasn’t sure if these were related. Its not letting me delete my other topic but I just wanted to give you a heads up.

@austinmcnicholas

We try our best to deal with every customer request in a timely fashion, we unfortunately cannot guarantee a delivery date to every customer issue. We work on issues on a first come, first served basis. We feel this is the fairest and most appropriate way to satisfy the needs of the majority of our customers.

Currently, your issue is pending for analysis and is in the queue. Once we complete the analysis of your issue, we will then be able to provide you an estimate.

@austinmcnicholas

It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-18719) as ‘Not a Bug’.

Please use the following Regex in your code to get the desired output.

Regex pattern = new Regex(@"{-[^{^&p].*?-}");