作者:NewGuy | 来源:互联网 | 2023-01-31 07:25
我有这个输入字符串:
Hello context61 Hi: context:file/ hello context715: context666:file/ foo
我的目标是将每次出现的替换(清理)替换context[anything]:
为空字符串.这anything
部分可能是空的.
输出应如下所示:
Hello context61 Hi: file/ hello file/ foo
我尝试过无尽的尝试,但在正则表达方面我只是一个菜鸟.有人可以帮忙吗?
1> Potatoツ..:
试试下面的Vbscript代码:
str="Hello context61 Hi: context:file/ hello context715: context666:file/ foo"
Set oreg = New RegExp
oreg.IgnoreCase=False
oreg.Global=True
oreg.Pattern="context\d*\:" 'context followed by 0 or more digits followed by colon
'oreg.Pattern="context[a-zA-Z0-9]*?\:" 'or we can have this as pattern which will cover alphabets too
result = oreg.Replace(str,"") 'replaces every matched pattern in the string 'str' by an empty string
MsgBox result
输出: