netchx/netch · warning · MessageException

Above rules does not conform to C++ regular expression synta

Error message

Above rules does not conform to C++ regular expression syntax

What it means

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.

Source

Thrown at Netch/Controllers/NFController.cs:143

    private void DialRule()
    {
        Dial(NameList.AIO_CLRNAME, "");
        var invalidList = new List<string>();
        foreach (var s in _mode.Bypass)
        {
            if (!Dial(NameList.AIO_BYPNAME, s))
                invalidList.Add(s);
        }

        foreach (var s in _mode.Handle)
        {
            if (!Dial(NameList.AIO_ADDNAME, s))
                invalidList.Add(s);
        }

        if (invalidList.Any())
            throw new MessageException(GenerateInvalidRulesMessage(invalidList));

        // Bypass Self
        Dial(NameList.AIO_BYPNAME, "^" + Global.NetchDir.ToRegexString());
    }

    #region DriverUtil

    private static void CheckDriver()
    {
        var binFileVersion = Utils.Utils.GetFileVersion(Constants.NFDriver);
        var systemFileVersion = Utils.Utils.GetFileVersion(SystemDriver);

        Log.Information("Built-in  netfilter2 driver version: {Name}", binFileVersion);
        Log.Information("Installed netfilter2 driver version: {Name}", systemFileVersion);

        if (!File.Exists(SystemDriver))
        {
            // Install

View on GitHub (pinned to 9d99eb1c5a)

Solutions

  1. Read the listed rules in the message — each invalid entry is printed.
  2. Fix or remove the offending regex in the mode's Bypass/Handle editor.
  3. Validate rules ahead of time with NFController.CheckRules(rules, out var bad) which returns the failing subset without starting the engine.
  4. Test the regex in a std::regex-compatible tester before importing.

Example fix

// before (unbalanced group -> rejected)
_mode.Bypass = new[] { "foo(bar" };
// after
_mode.Bypass = new[] { "foo(bar)" };
Defensive patterns

Strategy: validation

Validate before calling

// Validate all rules against the engine BEFORE starting.
var allRules = mode.Bypass.Concat(mode.Handle);
if (!NFController.CheckRules(allRules, out var invalid))
    throw new MessageException(NFController.GenerateInvalidRulesMessage(invalid));

Try / catch

try { await nfController.StartAsync(server, mode); }
catch (MessageException ex) when (ex.Message.Contains("regular expression syntax"))
{
    // ex.Message lists the offending rules; send the user back to the rule editor.
    OpenRuleEditorWithErrors(ex.Message);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of netchx/netch@9d99eb1c5a (2026-08-13). Data as JSON: /api/errors/9dae07bcc464f21b. Report an issue: GitHub.