Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

ReplaceText does not work with regex #59

Open
scottone opened this issue May 27, 2021 · 1 comment
Open

ReplaceText does not work with regex #59

scottone opened this issue May 27, 2021 · 1 comment

Comments

@scottone
Copy link

I can find text using a Regex (Paragraph.FindAllByPattern function) but
cannot replace text with a Regex (Paragraph.ReplaceText function). Am I missing something?

This matches the text:
$WordDocument.Paragraphs[2].FindAllByPattern('E.*?e',[System.Text.RegularExpressions.RegexOptions]::None)

This uses the same pattern but does not do the replacement:
$WordDocument.Paragraphs[2].ReplaceText('E.*?e','Awesomeness', $false, [System.Text.RegularExpressions.RegexOptions]::None)

@PrzemyslawKlys
Copy link
Member

Could it be related to formatting? In theory DocX fixed that in version 1.4.1 (https://github.com/xceedsoftware/DocX/wiki/Release-Notes-v1.4.1) which we use but maybe it requires an additional option? You could try replacing DLL with the new version and seeing if it fixes your issue - the problem is - there were a lot of changes that may break different functionality. Normally I would go and update PSWriteWord to the newest DLL but the license change they did is risky for us and I am struggling whether to make a change or not. I would suggest to maybe use power of PowerShell and just go thru Paragraph yourself, get all the content and do regex in PowerShell rather then pass it to DocX?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants