Repository: microsoft/ApplicationInspector
File: AppInspector.RulesEngine/RulesVerifier.cs (C#)

Code before:
                errors.Add(MsgHelp.FormatString(MsgHelp.ID.VERIFY_RULES_REGEX_FAIL, rule.Id ?? "", pattern ?? "",
                    e.Message));
            }

        //valid search pattern
        foreach (var searchPattern in rule.Patterns ?? Array.Empty<SearchPattern>())
        {
            if (searchPattern.PatternType == PatternType.RegexWord || searchPattern.PatternType == PatternType.Regex)
            {
                RegexOptions regexOpts = Utils.RegexModifierToRegexOptions(searchPattern.Modifiers, _options.EnableNonBacktrackingRegex);
                try
                {
                    if (string.IsNullOrEmpty(searchPattern.Pattern))
                    {
                        throw new ArgumentException();
                    }
                                        
                    _ = new Regex(searchPattern.Pattern, regexOpts);
                }
                catch (NotSupportedException e)
                {
                    // Regex requires backtracking, try without non-backtracking
                    _logger?.LogWarning(MsgHelp.GetString(MsgHelp.ID.VERIFY_RULES_REGEX_FAIL), rule.Id ?? "", searchPattern.Pattern ?? "", e.Message);
#if NET7_0_OR_GREATER
                    // remove non-backtracking flag by applying XOR
                    regexOpts ^= RegexOptions.NonBacktracking;
#endif

                    _ = new Regex(searchPattern.Pattern, regexOpts);      
                }
                catch (Exception e)
                {
                    _logger?.LogError(MsgHelp.GetString(MsgHelp.ID.VERIFY_RULES_REGEX_FAIL), rule.Id ?? "",
                        searchPattern.Pattern ?? "", e.Message);
                    errors.Add(MsgHelp.FormatString(MsgHelp.ID.VERIFY_RULES_REGEX_FAIL, rule.Id ?? "",
                        searchPattern.Pattern ?? "", e.Message));
                }
            }

            if (searchPattern.JsonPaths is not null)
            {
                foreach (var jsonPath in searchPattern.JsonPaths)
                {
                    try
                    {
                        _ = JsonSelector.Parse(jsonPath);
                    }
                    catch (Exception e)
                    {
                        _logger?.LogError(
                            "The provided JsonPath '{JsonPath}' value was not valid in Rule {Id} : {message}",

Review comment (bug):
```suggestion
                    regexOpts &= ~RegexOptions.NonBacktracking;
```

I think its a bit clearer to just not the specific bit rather than xoring. Xoring also has the side effect of turning on non-backtracking if it was not already on, in the case that something else caused the `NotSupportedException`.  I suspect there may be other flag combinations or query input that can cause that throw. This could cause the second exception to fail with a deceptive error about NonBacktracking when the user hasn't specified it.

Code after:

        return ruleStatuses;
    }

    public RuleStatus CheckIntegrity(ConvertedOatRule convertedOatRule)
    {
        List<string> errors = new();

        // App Inspector checks
        var rule = convertedOatRule.AppInspectorRule;
        // Check for null Id
        if (string.IsNullOrEmpty(rule.Id))
        {
            _logger.LogError(MsgHelp.GetString(MsgHelp.ID.VERIFY_RULES_NULLID_FAIL), rule.Name);
            errors.Add(MsgHelp.FormatString(MsgHelp.ID.VERIFY_RULES_NULLID_FAIL, rule.Name));
        }

        //applicability
        if (rule.AppliesTo != null)
        {
            var languages = _options.LanguageSpecs.GetNames();
            // Check for unknown language
            foreach (var lang in rule.AppliesTo)
                if (!string.IsNullOrEmpty(lang))
                {
                    if (!languages.Any(x => x.Equals(lang, StringComparison.CurrentCultureIgnoreCase)))
                    {
                        _logger.LogError(MsgHelp.GetString(MsgHelp.ID.VERIFY_RULES_LANGUAGE_FAIL), rule.Id ?? "", lang);
                        errors.Add(MsgHelp.FormatString(MsgHelp.ID.VERIFY_RULES_LANGUAGE_FAIL, rule.Id ?? "", lang));
                    }
                }
        }

        // Check that regexes for filenames are valid
        foreach (var pattern in (IList<string>?)rule.FileRegexes ?? Array.Empty<string>())
            try
            {
                _ = new Regex(pattern, RegexOptions.Compiled);
            }
            catch (Exception e)
            {
                _logger?.LogError(MsgHelp.GetString(MsgHelp.ID.VERIFY_RULES_REGEX_FAIL), rule.Id ?? "", pattern ?? "",
                    e.Message);
                errors.Add(MsgHelp.FormatString(MsgHelp.ID.VERIFY_RULES_REGEX_FAIL, rule.Id ?? "", pattern ?? "",
                    e.Message));
            }

        //valid search pattern
        foreach (var searchPattern in rule.Patterns ?? Array.Empty<SearchPattern>())
        {
            // Check that pattern regex arguments are valid