stride3d/stride · error · NotImplementedException

Can't match pattern that uses '['

Error message

Can't match pattern that uses '['

What it means

PathSelector.TransformToRegex translates a glob-like selector pattern into a regular expression. The '[' character (character-class syntax) is not supported by this glob dialect, so encountering it throws NotImplementedException. The library explicitly refuses patterns it cannot translate rather than producing a wrong regex.

Solutions

  1. Rewrite the pattern using only '*', '?' and '**' constructs supported by PathSelector instead of character classes.
  2. If a literal '[' must be matched, escape or restructure the pattern to avoid '[' (e.g. use '?' as a single-char wildcard: 'item?.bin').
  3. Pre-filter the file list yourself with a real regex and skip PathSelector for character-class needs.
  4. Check the file/path names: if assets genuinely contain brackets, rename them or handle selection outside the selector.

Example fix

// before
var selector = new PathSelector("assets/[a-z]*.png");

// after
var selector = new PathSelector("assets/*.png"); // filter case/detail with additional code
Defensive patterns

Strategy: validation

Validate before calling

if (pattern.Contains('['))
    throw new ArgumentException("PathSelector patterns do not support '[' character classes; use *, ?, or ** only.", nameof(pattern));

Try / catch

try { selector.Select(paths); }
catch (NotImplementedException) { /* fall back to Regex-based matching */ }

Prevention

When it happens

Trigger: Calling Select (e.g. new PathSelector(pattern).Select(...)) with a pattern containing '[', such as "assets/[a-z]*.png" or a bracketed directory name like "lib[1]/".

Common situations: Writing shell-style glob patterns assuming full glob support; selecting files whose actual names contain literal brackets (e.g. "item[1].bin"); porting glob expressions from other tools that support character classes.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/3d07133da9f56085. Report an issue: GitHub.

Appendix: source

Thrown at sources/assets/Stride.Core.Assets/Selectors/PathSelector.cs:102

            switch (c)
            {
                case '*':
                    // Match everything (except '/')
                    result.Append("[^/]*");
                    break;
                case '?':
                    // Match a single character (except '/')
                    result.Append("[^/]");
                    break;
                case '\\':
                    // If not last character, escape next one
                    if (++i < pattern.Length)
                        c = pattern[i];

                    // Default case (add character as is)
                    goto default;
                case '[':
                   throw new NotImplementedException("Can't match pattern that uses '['");
                default:
                    result.Append(Regex.Escape(c.ToString()));
                    break;
            }
        }

        // If there is no '/' at the end, it must either finish or have another path after
        if (pattern.Length > 0 && pattern[^1] != '/')
        {
            result.Append(@"($|/)");
        }
        return result.ToString();
    }
}

View on GitHub (pinned to 96fad776d2)