正则表达式替换正文内容 [英] Regular expression replace body content
本文介绍了正则表达式替换正文内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了以下操作,将当前打开的文档中的所有文本内容替换为数字零,但是它不起作用
I tried the following to replace all the text content in the current open document with numeric zero, but it doesn't work
Set objWdDoc = Word.Application.ActiveDocument
Set objWdRange = objWdDoc.Content
Dim re As New RegExp
re.Global = True
re.Pattern = "[a-z]"
re.IgnoreCase = True
objWdRange = re.Replace(objWdRange, "0")
有人可以建议一种可行的方法吗?
Can anyone suggest a working method?
推荐答案
假定您已引用 microsoft vbscript正则表达式
objWdRange.Text = re.Replace(objWdRange, "0")
会工作的,尽管您当然会丢失任何格式.
Will work, although you will of course lose any formatting.
您还可以使用内置的搜索/替换功能,该功能对查找数字/字符的支持有限.记录下自己执行此操作的宏,即可检查代码.
You can also use the built-in search/replace which has limited support to find digits/characters. Record a macro of yourself doing this and you can examine the code.
这篇关于正则表达式替换正文内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文