Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 弥补Office COM中Find.Execute的缺点_Powershell_Office Interop - Fatal编程技术网

Powershell 弥补Office COM中Find.Execute的缺点

Powershell 弥补Office COM中Find.Execute的缺点,powershell,office-interop,Powershell,Office Interop,考虑到Find.Execute不允许使用RegEx,除了将段落流式输出并逐个遍历之外,还有什么COM方法可以做到这一点吗 我需要在Word文档中找到正则表达式模式,并最好返回匹配项。如果做不到这一点,请在Word文档中找到一个正则表达式,并至少返回$True,以便捕获它 注意:我意识到之所以Find.Execute有限是因为它是对“Find text”对话框的调用,但我希望有一些类似的有效方法来搜索模式Find.Execute相当快,将文档中的文本作为一个范围进行流式输出,然后在其中进行搜索。什

考虑到
Find.Execute
不允许使用RegEx,除了将段落流式输出并逐个遍历之外,还有什么COM方法可以做到这一点吗

我需要在Word文档中找到正则表达式模式,并最好返回匹配项。如果做不到这一点,请在Word文档中找到一个正则表达式,并至少返回$True,以便捕获它


注意:我意识到之所以
Find.Execute
有限是因为它是对“Find text”对话框的调用,但我希望有一些类似的有效方法来搜索模式
Find.Execute
相当快,将文档中的文本作为一个范围进行流式输出,然后在其中进行搜索。

什么时候
Find.Execute
停止使用正则表达式

$wd = New-Object -COM "Word.Application"

...

$fnd = $wd.Selection.Find

$fnd.Text = "..."  # replace with your pattern
$fnd.MatchWildcards = True
...
$fnd.Execute

语法只是标准正则表达式的一个例子。

您回答了这个问题:“什么时候找到的。执行停止允许正则表达式?”您回答说:它从来没有找到过。通配符不是正则表达式。在我使用它们的时候,它们的功能不如[regex]调用,而且语法也有很大的不同,学习它们是一种负担。然而,对于我的用例,我想我会咬紧牙关,学习细节以重新获得速度优势。