<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace ClosedXML.Excel
{
    using System.Text.RegularExpressions;

    internal class XLNamedRange: IXLNamedRange
    {
        private static readonly Regex _namedRangeReferenceRegex =
            new Regex(
                @"^('?(?<Sheet>[^'!]+)'?!(?<Range>.+))|((?<Table>[^\[]+)\[(?<Column>[^\]]+)\])$",
                RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture
            );
        private readonly List<String> _rangeList = new List<String>();
        private readonly XLNamedRanges _namedRanges;
        public XLNamedRange(XLNamedRanges namedRanges , String rangeName, String range,  String comment = null)
        {
            Name = rangeName;
            _rangeList.Add(range);
            Comment = comment;
            _namedRanges = namedRanges;
        }

        public XLNamedRange(XLNamedRanges namedRanges, String rangeName, IXLRanges ranges, String comment = null)
        {
            Name = rangeName;
            ranges.ForEach(r => _rangeList.Add(r.RangeAddress.ToStringFixed(XLReferenceStyle.A1)));
            Comment = comment;
            _namedRanges = namedRanges;
        }

        public String Name { get; set; }
        public IXLRanges Ranges
        {
            get
            {
                var ranges = new XLRanges();
                                foreach (var rangeToAdd in 
                   from rangeAddress in _rangeList 
                   let match = _namedRangeReferenceRegex.Match(rangeAddress)
                   select
                       match.Groups["Sheet"].Success<commit_msg>Fixed bug when adding named ranges<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace ClosedXML.Excel
{
    using System.Text.RegularExpressions;

    internal class XLNamedRange: IXLNamedRange
    {
        private static readonly Regex _namedRangeReferenceRegex =
            new Regex(
                @"^('?(?<Sheet>[^'!]+)'?!(?<Range>.+))|((?<Table>[^\[]+)\[(?<Column>[^\]]+)\])$",
                RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture
            );
        private readonly List<String> _rangeList = new List<String>();
        private readonly XLNamedRanges _namedRanges;
        public XLNamedRange(XLNamedRanges namedRanges , String rangeName, String range,  String comment = null)
        {
            Name = rangeName;
            _rangeList.Add(range);
            Comment = comment;
            _namedRanges = namedRanges;
        }

        public XLNamedRange(XLNamedRanges namedRanges, String rangeName, IXLRanges ranges, String comment = null)
        {
            Name = rangeName;
            ranges.ForEach(r => _rangeList.Add(r.RangeAddress.ToStringFixed(XLReferenceStyle.A1, true)));
            Comment = comment;
            _namedRanges = namedRanges;
        }

        public String Name { get; set; }
        public IXLRanges Ranges
        {
            get
            {
                var ranges = new XLRanges();
                                foreach (var rangeToAdd in 
                   from rangeAddress in _rangeList 
                   let match = _namedRangeReferenceRegex.Match(rangeAddress)
                   select
                       match.Groups["Sheet"].Success
{'fraction_non_alphanumeric': 0.0961254066844129, 'fraction_numerical': 0.0005915409642117716, 'mean_word_length': 1.9797356828193833, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3833946', 'n_tokens_mistral': 916, 'n_tokens_neox': 859, 'n_words': 197}