I just found Apache POI library very useful for editing Word files using Java. Specifically, I want to edit a DOCX file using Apache POI\'s XWPF classes. I
I suggest my solution for replacing text between #, for example: This #bookmark# should be replaced. It is replace in:
Also, it takes into account situations, when symbol # and bookmark are in the separated runs (replace variable between different runs).
Here link to the code: https://gist.github.com/aerobium/bf02e443c079c5caec7568e167849dda