扩展正则表达式(ERE).gitignore [英] Extended regular expressions (ERE) for .gitignore

查看:197
本文介绍了扩展正则表达式(ERE).gitignore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在 .gitignore 文件中使用扩展正则表达式(ERE)的方法?例如,我想在 .gitignore 文件中使用 + 重复字符。有没有办法做到这一点?

解决方案

如图所示这里,并在这个问题中详细说明, fnmatch()涉及解释glob模式,这意味着不支持正则表达式。 p>

这就是 gitignore 手册页提及:


否则, git将模式视为(3) FNM_PATHNAME 标记一起使用的shell glob:模式中的通配符不会匹配 / 在路径名中。

例如, Documentation / *。html 匹配文档/git.html 但不是 Documentati on / ppc / ppc.html tools / perf / Documentation / perf.html

您可以在那些 问题


Is there a way to use extended regular expressions(ERE) in a .gitignore file? For example I want to use the + repetition character in a .gitignore file. Is there a way to do that?

解决方案

As illustrated here and detailed in "this question", the function fnmatch() is involved to interpret glob patterns, which means regular expressions are not supported.

This is what gitignore man page mentions:

Otherwise, git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname.
For example, "Documentation/*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html" or "tools/perf/Documentation/perf.html".

You can see some correspondence between glob patterns and regular expressions in those questions.

这篇关于扩展正则表达式(ERE).gitignore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆