Exemplo n.º 1
0
        public RegExpArray exec(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return(null);
            }

            string value = this.lastIndex > 0 ? input.Substring(this.lastIndex) : input;
            Match  match = this.Match(value);

            if (this.global)
            {
                this.lastIndex = match.Success ? match.Index + match.Length : 0;
            }
            if (match.Success)
            {
                RegExpArray ret = new RegExpArray();
                foreach (Group g in match.Groups)
                {
                    if (g.Success)
                    {
                        ret.Add(g.Value);
                    }
                    else
                    {
                        ret.Add(null);
                    }
                }
                ret.input = input;
                ret.index = match.Index;
                return(ret);
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="regex"></param>
        /// <returns></returns>
        public RegExpArray match(RegExp regex)
        {
            this.CheckUndefined();

            string input = GetText(this);

            if (!regex.IsMatch(input))
            {
                return(null);
            }

            RegExpArray ret = new RegExpArray();

            if (regex.global)
            {
                foreach (Match match in regex.Matches(input))
                {
                    ret.Add(match.Value);
                }
            }
            else
            {
                Match match = regex.Match(input);
                foreach (Group g in match.Groups)
                {
                    ret.Add(g.Value);
                }
                ret.input = input;
                ret.index = match.Index;
            }

            return(ret);
        }