在 Mac 上使用 Excel VBA 进行正则表达式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27344932/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
RegEx with Excel VBA on Mac
提问by Gersee
I need to use regEx with Excel VBA. I'm using Mac OS 10.10 and Office 2011. So there is no DLL file I can use.
我需要在 Excel VBA 中使用 regEx。我使用的是 Mac OS 10.10 和 Office 2011。所以没有我可以使用的 DLL 文件。
What is there to do here?
这里有什么可做的?
I read I've to bind an apple script. How is this done and what content does this script need?
我读到我必须绑定一个苹果脚本。这是如何完成的,这个脚本需要什么内容?
回答by BambiLongGone
You can use VBA's Like
operator. It's a very limited regex tester only.
您可以使用 VBA 的Like
运算符。它只是一个非常有限的正则表达式测试器。
Microsoft Word has it's standard wildcards plus if you tick Use Wildcards it is a Regex engine (plus find words that sound the same, and words with the same root). So use Word rather than Vbscript's RegEx.
Microsoft Word 有它的标准通配符,如果你勾选使用通配符,它是一个正则表达式引擎(加上查找发音相同的单词,以及具有相同词根的单词)。所以使用 Word 而不是 Vbscript 的 RegEx。
Just record a Find and Replace in Word and you'll get most of the program written for you that you'll just need to adapt.
只需在 Word 中记录一个查找和替换,您就会获得大部分为您编写的程序,您只需要对其进行调整即可。
回答by Sam
Natively, you can't really - AppleScript isn't actually that good for this kind of thing (where VBA is concerned)
本质上,你不能真的 - AppleScript 对于这种事情实际上并不是那么好(在 VBA 中)
There are other libraries that you can install and use to allow support for things like regular expressions on Mac OS - the one I've seen used the most is Satimage although I've not personally had to use it (yet) so can't vouch for it myself:
您可以安装和使用其他库来支持 Mac OS 上的正则表达式之类的东西 - 我见过使用最多的库是 Satimage 虽然我个人还没有使用它(还)所以不能我自己担保:
http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html
http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html
回答by game writer guy
I'm working on this problem too and I think Advanced Filters may be your answer if you want to do it in Excel without adding an external library. You can access it through VBA and set up a hidden sheet somewhere to stash your filters.
我也在解决这个问题,如果您想在 Excel 中执行此操作而不添加外部库,我认为高级过滤器可能是您的答案。您可以通过 VBA 访问它并在某处设置一个隐藏表来隐藏您的过滤器。
https://searchengineland.com/advanced-filters-excels-amazing-alternative-to-regex-143680
https://searchengineland.com/advanced-filters-excels-amazing-alternative-to-regex-143680
And you can see what it looks like in VBA here: https://www.contextures.com/exceladvancedfiltervba.html
你可以在这里看到它在 VBA 中的样子:https: //www.contextures.com/exceladvancedfiltervba.html
However, Advanced Filters does have some notable shortcomings, like the inability to distinguish a digit from a letter. The LIKE command mentioned earlier DOES have this ability however - so you could combine them to overcome that limitation.
但是,高级过滤器确实有一些明显的缺点,例如无法区分数字和字母。然而,前面提到的 LIKE 命令确实具有这种能力 - 因此您可以将它们组合起来以克服该限制。
Hopefully you and I can both solve this problem using these tools...!
希望你我都能使用这些工具解决这个问题......!