与ANT模式语法和可能的变体混淆 [英] Confusion with ANT pattern syntax and possible variations

查看:120
本文介绍了与ANT模式语法和可能的变体混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为大型服务器项目的一部分,我正在研究ANT模式解析器.

I am working on an ANT pattern parser as part of a large server project.

此帖子的答案中有一些很好的ANT模式示例:

There are some good examples of ANT patterns in the answer to this post: How do I use Nant/Ant naming patterns? however, I am still confused about some possible permutations.

此处ANT模式文档中的示例之一 http://nant.sourceforge.net/release/0.85/help/types/fileset.html 如下:

One of the examples on the ANT pattern documentation here http://nant.sourceforge.net/release/0.85/help/types/fileset.html is as follows:

**/test/**匹配路径中包含test元素的所有文件,包括将test作为文件名.

**/test/** Matches all files that have a test element in their path, including test as a filename.

我的理解是**匹配一个或多个目录以及这些目录下的文件.因此,我希望**/test/**匹配src/test/subfolder/file.txttest/file2.txt,但是此语句似乎暗示它还将匹配名为src/test的文件.即使模式中test后面有/,这是否正确?

My understanding is that ** matches one or more directories and also files under those directories. So I would expect **/test/** to match src/test/subfolder/file.txt and test/file2.txt but this statement seems to imply that it would also match a file named src/test. Is this correct even though there is a / after the test in the pattern?

还不清楚以下模式是否有效:

Also, its not clear whether the following patterns would be valid:

folder**
folder1/folder**
**folder/file.txt

我想他们会和

folder*/**
folder1/folder*/**
**/*folder/file.txt

但是他们被允许吗?

推荐答案

我按照 coolcfan 的建议对NAnt进行了一些测试,并回答了我自己的问题.问题中的模式都是有效的.

I did some testing with NAnt as per coolcfan's suggestion and answered my own question. The patterns in the question are all valid.

基于上面我的问题链接中的以下文件:

Based on the following files from the link in my question above:

  1. bar.txt
  2. src/bar.c
  3. src/baz.c
  4. src/test/bartest.c

以下意外模式也有效:

  • src**             nbsp;  nbsp;  nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; b ,3和4
  • **.c              nbsp;  匹配2、3和4
  •                    匹配1和2
  • **/bartest.c/**匹配4
  • src/ba?.c/**      匹配2和3
  • src**                      matches 2, 3 and 4
  • **.c                        matches 2, 3, and 4
  • **ar.*                    matches 1 and 2
  • **/bartest.c/**  matches 4
  • src/ba?.c/**        matches 2 and 3

为完整起见,这些是在我上面的问题的链接中采用的以下模式的补充:

For completeness, these are in addition to the following patterns taken from the link in my question above:

  • *.c不匹配(当前目录中没有.c文件)
  • src/*.c   匹配2和3
  • */*.c       匹配2和3(因为*仅匹配一个级别)
  • **/*.c     匹配2、3和4(因为**匹配任意数量的级别)
  • bar.*       匹配1
  • **/bar.* 匹配1和2
  • **/bar*.*匹配1、2和4
  • src/ba?.c匹配2和3   &libsp;
  • *.c             matches nothing (there are no .c files in the current directory)
  • src/*.c     matches 2 and 3
  • */*.c         matches 2 and 3 (because * only matches one level)
  • **/*.c       matches 2, 3, and 4 (because ** matches any number of levels)
  • bar.*         matches 1
  • **/bar.*   matches 1 and 2
  • **/bar*.* matches 1, 2, and 4
  • src/ba?.c matches 2 and 3    

这篇关于与ANT模式语法和可能的变体混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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