Unity-Technologies/UnityCsReference · error · ArgumentException

Invalid Regular Expression in {filterName} for {fieldName}="

Error message

Invalid Regular Expression in {filterName} for {fieldName}="{value}": {e.Message}

What it means

Thrown by the obsolete VulkanDeviceFilter.CheckRegex method when the provided vendor name or filter string is not a valid .NET regular expression. The method attempts to construct a Regex from the input; if that throws ArgumentException (invalid regex syntax), it is re-thrown with a descriptive wrapper. This validates GPU device filter regex patterns before they reach the native side where an invalid regex could crash the game.

Source

Thrown at Editor/Mono/PlayerSettingsAndroid.bindings.cs:1008

            [Obsolete("CheckVersion is obsolete. Use VulkanDeviceFilterLists api instead.")]
            internal static void CheckVersion(string value, string filterName, string fieldName)
            {
                if (!validVersionString.IsMatch(value))
                    throw new ArgumentException($"Invalid version string in {filterName} for {fieldName}=\"{value}\": {versionErrorMessage}");
            }

            [Obsolete("CheckRegex is obsolete. Use VulkanDeviceFilterLists api instead.")]
            internal static void CheckRegex(string value, string filterName, string fieldName)
            {
                try
                {
                    // Try to create a regex from the input string to determine if it is a valid regex
                    Regex regex = new Regex(value);
                }
                catch (ArgumentException e)
                {
                    throw new ArgumentException($"Invalid Regular Expression in {filterName} for {fieldName}=\"{value}\": {e.Message}");
                }
            }

            [Obsolete("CheckAllFilterData is obsolete. Use VulkanDeviceFilterLists api instead.")]
            internal static void CheckAllFilterData(AndroidDeviceFilterData[] filterDataList, string filterName)
            {
                // The check will throw an exception if there's an issue with the data.
                // We need to check the data here, as an invalid regex on the native side, can crash the game.
                foreach (var filterData in filterDataList)
                {
                    if (!String.IsNullOrEmpty(filterData.vendorName))
                        CheckRegex(filterData.vendorName, filterName, vendorNameString);
                    if (!String.IsNullOrEmpty(filterData.deviceName))
                        CheckRegex(filterData.deviceName, filterName, deviceNameString);
                    if (!String.IsNullOrEmpty(filterData.brandName))
                        CheckRegex(filterData.brandName, filterName, brandNameString);
                    if (!String.IsNullOrEmpty(filterData.productName))
                        CheckRegex(filterData.productName, filterName, productNameString);

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Test the regex pattern independently with Regex.IsMatch("test", pattern) before assigning it to the filter.
  2. If the filter is meant to be a literal string (not a regex), escape regex metacharacters: Regex.Escape(vendorName).
  3. Migrate to the VulkanDeviceFilterLists API which replaces the obsolete CheckRegex method.

Example fix

// before
CheckRegex("Qualcomm[", filterName, fieldName); // unmatched bracket

// after
CheckRegex("Qualcomm", filterName, fieldName);
Defensive patterns

Strategy: try-catch

Validate before calling

try { var test = new Regex(value); CheckRegex(value, filterName, fieldName); }
catch (ArgumentException) { /* notify user of invalid regex */ }

Try / catch

try
{
    CheckRegex(value, filterName, fieldName);
}
catch (ArgumentException ex)
{
    Debug.LogError($"Invalid Vulkan device filter regex for {fieldName}: {ex.Message}");
}

Prevention

When it happens

Trigger: Calling CheckRegex with a string containing invalid regex syntax — e.g. unmatched brackets '[abc', invalid quantifiers 'a{2,1}', dangling backslash 'foo\', or invalid character classes. The input is typically a GPU vendor name filter like 'Qualcomm' or 'ARM.*' where a typo introduces regex metacharacters.

Common situations: Editing Vulkan device filter vendor name patterns in Android player settings; escaping issues in serialized filter data; copy-pasting filter strings from documentation with encoding artifacts; using the obsolete API after migration.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/c65454869b02781f. Report an issue: GitHub.