{"record":{"id":"9dae07bcc464f21b","repo":"netchx/netch","slug":"above-rules-does-not-conform-to-c-regular-expres","errorCode":null,"errorMessage":"Above rules does not conform to C++ regular expression syntax","messagePattern":"Above rules does not conform to C\\+\\+ regular expression syntax","errorType":"exception","errorClass":"MessageException","httpStatus":null,"severity":"warning","filePath":"Netch/Controllers/NFController.cs","lineNumber":143,"sourceCode":"\n    private void DialRule()\n    {\n        Dial(NameList.AIO_CLRNAME, \"\");\n        var invalidList = new List<string>();\n        foreach (var s in _mode.Bypass)\n        {\n            if (!Dial(NameList.AIO_BYPNAME, s))\n                invalidList.Add(s);\n        }\n\n        foreach (var s in _mode.Handle)\n        {\n            if (!Dial(NameList.AIO_ADDNAME, s))\n                invalidList.Add(s);\n        }\n\n        if (invalidList.Any())\n            throw new MessageException(GenerateInvalidRulesMessage(invalidList));\n\n        // Bypass Self\n        Dial(NameList.AIO_BYPNAME, \"^\" + Global.NetchDir.ToRegexString());\n    }\n\n    #region DriverUtil\n\n    private static void CheckDriver()\n    {\n        var binFileVersion = Utils.Utils.GetFileVersion(Constants.NFDriver);\n        var systemFileVersion = Utils.Utils.GetFileVersion(SystemDriver);\n\n        Log.Information(\"Built-in  netfilter2 driver version: {Name}\", binFileVersion);\n        Log.Information(\"Installed netfilter2 driver version: {Name}\", systemFileVersion);\n\n        if (!File.Exists(SystemDriver))\n        {\n            // Install","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/netchx/netch/blob/9d99eb1c5a2acbf2a34f2600f94242601019a300/Netch/Controllers/NFController.cs#L125-L161","documentation":"Thrown by NFController.DialRule when one or more entries in the mode's Bypass or Handle rule lists failed Dial(AIO_BYPNAME / AIO_ADDNAME). The native Redirector compiles each rule as a C++ regular expression; a rule that does not compile is collected into invalidList, and GenerateInvalidRulesMessage lists them followed by this suffix. The offending rules are echoed in the message.","triggerScenarios":"A Bypass/Handle rule contains invalid C++ regex syntax (unbalanced parenthesis, unsupported construct, stray quantifier); a rule uses PCRE-only features the embedded engine lacks; a '!' prefixed rule whose remainder is malformed.","commonSituations":"User hand-edited a Redirector mode's rule list; imported a mode authored for a different regex engine; copy-paste introduced stray characters; outdated rule syntax from an older Netch version.","solutions":["Read the listed rules in the message — each invalid entry is printed.","Fix or remove the offending regex in the mode's Bypass/Handle editor.","Validate rules ahead of time with NFController.CheckRules(rules, out var bad) which returns the failing subset without starting the engine.","Test the regex in a std::regex-compatible tester before importing."],"exampleFix":"// before (unbalanced group -> rejected)\n_mode.Bypass = new[] { \"foo(bar\" };\n// after\n_mode.Bypass = new[] { \"foo(bar)\" };","handlingStrategy":"validation","validationCode":"// Validate all rules against the engine BEFORE starting.\nvar allRules = mode.Bypass.Concat(mode.Handle);\nif (!NFController.CheckRules(allRules, out var invalid))\n    throw new MessageException(NFController.GenerateInvalidRulesMessage(invalid));","typeGuard":null,"tryCatchPattern":"try { await nfController.StartAsync(server, mode); }\ncatch (MessageException ex) when (ex.Message.Contains(\"regular expression syntax\"))\n{\n    // ex.Message lists the offending rules; send the user back to the rule editor.\n    OpenRuleEditorWithErrors(ex.Message);\n}","preventionTips":["Run NFController.CheckRules in the mode editor on save so invalid regex never reaches Start.","Use std::regex (ECMAScript) compatible syntax when authoring rules.","Escape literal dots/parentheses; balance every group.","Test imported mode rules in a regex tester before deploying."],"tags":["regex","mode-rules","redirector","validation"],"backgroundTag":null,"analyzedSha":"9d99eb1c5a2acbf2a34f2600f94242601019a300","analyzedAt":"2026-08-13T14:12:19.105Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}