Confusion with ANT pattern syntax and possible variations

≯℡__Kan透↙ 提交于 2019-12-07 16:04:08

问题


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

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.

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/** Matches all files that have a test element in their path, including test as a filename.

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

I would imagine that they would work the same as

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

but are they allowed?


回答1:


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

The following unexpected patterns are also valid:

  • 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             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    


来源:https://stackoverflow.com/questions/18211196/confusion-with-ant-pattern-syntax-and-possible-variations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!