简体   繁体   English

CAtlRegExp格式的正则表达式不起作用?

[英]Regular Expression in CAtlRegExp format not working?

I created a regular expression to capture Microsoft Office executables like so: 我创建了一个正则表达式来捕获Microsoft Office可执行文件,如下所示:

 .*(\\Microsoft Office\\Office)(\d){1,2}(\\)(WINWORD.EXE|EXCEL.EXE|POWERPNT.EXE|MSACCESS.EXE|OUTLOOK.EXE|VISIO.EXE|WINPROJ.EXE)$

Anyway it turns out that the software I'm using only supports the CAtlRegExp flavour of regular expressions, and the above does not work. 无论如何,事实证明我使用的软件仅支持正则表达式的CAtlRegExp风格,并且上述方法不起作用。

I'm looking at the following article for reference and using the tool to test my regular expression: https://www.codeproject.com/Articles/13320/Using-Regular-Expressions-in-MFC 我正在查看以下文章以供参考,并使用该工具测试我的正则表达式: https//www.codeproject.com/Articles/13320/Using-Regular-Expressions-in-MFC

An example path is: 示例路径是:

C:\\Program Files (x86)\\Microsoft Office\\Office14\\WINWORD.EXE C:\\ Program Files(x86)\\ Microsoft Office \\ Office14 \\ WINWORD.EXE

Can anybody assist? 有人可以帮忙吗?

Thanks. 谢谢。

It looks like you may use 看起来你可能会用

.*\\Microsoft Office\\Office\d\d?\\((WINWORD)|(EXCEL)|(POWERPNT)|(MSACCESS)|(OUTLOOK)|(VISIO)|(WINPROJ))\.EXE$

The point here is that all alternatives inside (...) must be also wrapped with parentheses and that the regex flavor does not support limited (interval) quantifiers, and {...} defines a capturing group with zero-based IDs. 这里的要点是(...)内的所有替代品也必须用括号括起来,并且正则表达式不支持有限(间隔)量词, {...}定义具有从零开始的ID的捕获组 \\d\\d? matches 1 or 2 digits. 匹配1或2位数。 See the docs you refer to : 查看您参考文档

You can note that the syntax is not exactly the same as in Perl. 您可以注意到语法与Perl中的语法不完全相同。 For example, the grouping operator is {}, while in Perl it is (), and it doesn't have the {n} (match exactly n times) as in the Perl syntax 例如, 分组运算符是{},而在Perl中它是(),并且它没有Perl语法中的{n}(恰好匹配n次)

Also note that a literal dot should be defined with \\. 另请注意,应使用\\.定义文字点\\. and it is a good idea to only use one \\.EXE after all the grouped alternatives. 并且在所有分组的替代方案之后仅使用一个\\.EXE是个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM