Use regex to search and replace in Word

Dear, I have a word file, it contains different length _ in documet. for example, like ____, _______, ___. So how can I use regex to search them in Word use python? And replace them into other text? Thanks

@ZZZ21321 You can use Range.replace_regex method to achieve this. For example see the following code:

doc = aw.Document("C:\\Temp\\in.docx");
doc.range.replace_regex("_+", "replaced")
doc.save("C:\\Temp\\out.docx")

Thanks. I have a question, in raw python maybe I can use this code to dynamic replace. for example

import re
doc = re.sub("_+", lamda x: x.group().count("_") + "replace", doc)

So how can I do this in aspose word?

@ZZZ21321 In .NET and java versions of Aspose.Words you can achieve this using IReplacingCallback. Unfortunately, this functionality is not yet available in Python version. The feature request is logged as WORDSNET-24685. We will keep you informed and let you know once is is implemented.