{"record":{"id":"c65454869b02781f","repo":"Unity-Technologies/UnityCsReference","slug":"invalid-regular-expression-in-filtername-for-fi","errorCode":null,"errorMessage":"Invalid Regular Expression in {filterName} for {fieldName}=\"{value}\": {e.Message}","messagePattern":"Invalid Regular Expression in (.+?) for (.+?)=\"(.+?)\": (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/PlayerSettingsAndroid.bindings.cs","lineNumber":1008,"sourceCode":"\n            [Obsolete(\"CheckVersion is obsolete. Use VulkanDeviceFilterLists api instead.\")]\n            internal static void CheckVersion(string value, string filterName, string fieldName)\n            {\n                if (!validVersionString.IsMatch(value))\n                    throw new ArgumentException($\"Invalid version string in {filterName} for {fieldName}=\\\"{value}\\\": {versionErrorMessage}\");\n            }\n\n            [Obsolete(\"CheckRegex is obsolete. Use VulkanDeviceFilterLists api instead.\")]\n            internal static void CheckRegex(string value, string filterName, string fieldName)\n            {\n                try\n                {\n                    // Try to create a regex from the input string to determine if it is a valid regex\n                    Regex regex = new Regex(value);\n                }\n                catch (ArgumentException e)\n                {\n                    throw new ArgumentException($\"Invalid Regular Expression in {filterName} for {fieldName}=\\\"{value}\\\": {e.Message}\");\n                }\n            }\n\n            [Obsolete(\"CheckAllFilterData is obsolete. Use VulkanDeviceFilterLists api instead.\")]\n            internal static void CheckAllFilterData(AndroidDeviceFilterData[] filterDataList, string filterName)\n            {\n                // The check will throw an exception if there's an issue with the data.\n                // We need to check the data here, as an invalid regex on the native side, can crash the game.\n                foreach (var filterData in filterDataList)\n                {\n                    if (!String.IsNullOrEmpty(filterData.vendorName))\n                        CheckRegex(filterData.vendorName, filterName, vendorNameString);\n                    if (!String.IsNullOrEmpty(filterData.deviceName))\n                        CheckRegex(filterData.deviceName, filterName, deviceNameString);\n                    if (!String.IsNullOrEmpty(filterData.brandName))\n                        CheckRegex(filterData.brandName, filterName, brandNameString);\n                    if (!String.IsNullOrEmpty(filterData.productName))\n                        CheckRegex(filterData.productName, filterName, productNameString);","sourceCodeStart":990,"sourceCodeEnd":1026,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/PlayerSettingsAndroid.bindings.cs#L990-L1026","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Test the regex pattern independently with Regex.IsMatch(\"test\", pattern) before assigning it to the filter.","If the filter is meant to be a literal string (not a regex), escape regex metacharacters: Regex.Escape(vendorName).","Migrate to the VulkanDeviceFilterLists API which replaces the obsolete CheckRegex method."],"exampleFix":"// before\nCheckRegex(\"Qualcomm[\", filterName, fieldName); // unmatched bracket\n\n// after\nCheckRegex(\"Qualcomm\", filterName, fieldName);","handlingStrategy":"try-catch","validationCode":"try { var test = new Regex(value); CheckRegex(value, filterName, fieldName); }\ncatch (ArgumentException) { /* notify user of invalid regex */ }","typeGuard":null,"tryCatchPattern":"try\n{\n    CheckRegex(value, filterName, fieldName);\n}\ncatch (ArgumentException ex)\n{\n    Debug.LogError($\"Invalid Vulkan device filter regex for {fieldName}: {ex.Message}\");\n}","preventionTips":["Test regex patterns with Regex.IsMatch or new Regex() before assigning to filters.","Escape literal strings with Regex.Escape() if they are not intended as regex.","Migrate to the VulkanDeviceFilterLists API to replace the obsolete CheckRegex."],"tags":["unity-editor","android","vulkan","regex-validation","obsolete-api"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}