I am working on functionality that allows the user to specify a “wildcard” path for items in a folder hierarchy and the associated action that will be performed when an item matches this path. eg:.
Path Action ----------- ------- 1. $/foo/*/baz include 2. $/foo/bar/* exclude
Now with the example above, the element in $/foo/bar/baz will correspond to both actions. Given this, I want to give a rough assessment of the specificity of the wildcard pattern, which will be based on the "depth" in which the first wildcard character occurs. The path with the greatest depth will triumph. It is important to note that only * limited by forward slashes ( /*/ ) is allowed as a wildcard (except when /* at the end), and any number can be specified at different points on the path.
TL DR;
So, I think the regex to count the number of slashes before the first * is the way to go. However, for a number of reasons, when there is no pattern in the path, the slash will be zero. I have the following negative view:
(?<!\*.*)/
which works great when there are wildcards (for example, 2 forward slashes for path number 1 above and 3 for # 2), but when there is no wildcard, it naturally matches all the slashes. I am sure this is a simple step to match none, but due to the rusty regular expression skills that I'm stuck with.
Ideally, from an academic point of view, I would like to see if one regular expression can capture this, however bonus points are offered for a more elegant solution to the problem!
source share