No more pattern data allowed after {*…} or ** pattern element

Error: no more pattern data allowed after {*…} or ** pattern element

This error typically occurs when working with path patterns or glob patterns in various programming languages or libraries. It indicates that there is a syntax error or invalid usage of the pathology or globbing pattern.

Path patterns are used to match and manipulate file or directory paths based on certain criteria. They usually involve the use of wildcards, such as “*”, “?”, or “**”, to represent one or more characters. These wildcards play crucial roles in defining the pattern rules for matching paths.

Here is an example that demonstrates the error scenario:

        let pattern = "src/**/*.js/*";
        let matchedPaths = someFunction(pattern);
        console.log(matchedPaths);
    

In this example, the pattern “src/**/*.js/*” is invalid because it contains both “{*…}” and “**” pattern elements consecutively. The “{*…}” pattern, also known as “brace expansion”, allows multiple alternatives to be specified, while the “**” pattern matches zero or more directories. However, these two patterns cannot be used together as they conflict with each other.

To resolve this issue, you need to reconsider your pattern and choose either “{*…}” or “**” but not both. For example:

        // Option 1: Use brace expansion
        let pattern = "src/{folder1,folder2}/**/*.js";
        let matchedPaths = someFunction(pattern);
        console.log(matchedPaths);
        
        // Option 2: Use double wildcards
        let pattern = "src/**/*.js";
        let matchedPaths = someFunction(pattern);
        console.log(matchedPaths);
    

In Option 1, the pattern “src/{folder1,folder2}/**/*.js” will match any “.js” file inside “folder1” or “folder2” located under the “src” directory. Meanwhile, Option 2 uses the pattern “src/**/*.js” to match any “.js” file in any subdirectory of “src”.

Correcting the pattern will allow you to achieve the desired path matching behavior without triggering the error.

Read more

Leave a comment