Example #1
0
        bool CheckBalancedGroup(RegexBuffer buffer)
        {
            // look for ?<Name1-Name2> or ?'Name1-Name2' syntax...
            // look for ?<Name> or ?'Name' syntax...
            Regex regex = new Regex(@"
				        ^                         # anchor to start of string
						\?[\<|']                  # ?< or ?'
						(?<Name1>[a-zA-Z]+?)       # Capture name1
						-
						(?<Name2>[a-zA-Z]+?)       # Capture name2
						[\>|']                    # ?> or ?'
						(?<Rest>.+)               # The rest of the expression
						"                        ,
                                    RegexOptions.IgnorePatternWhitespace);

            Match match = regex.Match(buffer.String);

            if (match.Success)
            {
                description    = String.Format("Balancing Group <{0}>-<{1}>", match.Groups["Name1"], match.Groups["Name2"]);
                buffer.Offset += match.Groups["Rest"].Index;
                expression     = new RegexExpression(buffer);
                CheckClosingParen(buffer);
                return(true);
            }
            return(false);
        }
Example #2
0
        bool CheckNamed(RegexBuffer buffer)
        {
            Regex regex;
            Match match;

            // look for ?<Name> or ?'Name' syntax...
            regex = new Regex(@"
				        ^                         # anchor to start of string
						\?(\<|')                  # ?< or ?'
						(?<Name>[a-zA-Z0-9]+?)    # Capture name
						(\>|')                    # ?> or ?'
						(?<Rest>.+)               # The rest of the string
						"                        ,
                              RegexOptions.IgnorePatternWhitespace);

            match = regex.Match(buffer.String);
            if (match.Success)
            {
                description = String.Format("Capture to <{0}>", match.Groups["Name"]);

                // advance buffer to the rest of the expression
                buffer.Offset += match.Groups["Rest"].Index;
                expression     = new RegexExpression(buffer);

                CheckClosingParen(buffer);
                return(true);
            }
            return(false);
        }
Example #3
0
        bool HandlePlainOldCapture(RegexBuffer buffer)
        {
            // we're already at the expression. Just create a new
            // expression, and make sure that we're at a ")" when
            // we're done
            if (buffer.ExplicitCapture)
            {
                description = String.Format("Non-capturing Group");
            }

            expression = new RegexExpression(buffer);
            CheckClosingParen(buffer);
            return(true);
        }
Example #4
0
        bool CheckLookahead(RegexBuffer buffer)
        {
            Regex regex = new Regex(@"
				        ^                         # anchor to start of string
						\?
						(?<Assertion><=|<!|=|!)   # assertion char
						(?<Rest>.+)               # The rest of the expression
						"                        ,
                                    RegexOptions.IgnorePatternWhitespace);

            Match match = regex.Match(buffer.String);

            if (match.Success)
            {
                switch (match.Groups["Assertion"].Value)
                {
                case "=":
                    description = "zero-width positive lookahead";
                    break;

                case "!":
                    description = "zero-width negative lookahead";
                    break;

                case "<=":
                    description = "zero-width positive lookbehind";
                    break;

                case "<!":
                    description = "zero-width negative lookbehind";
                    break;
                }
                buffer.Offset += match.Groups["Rest"].Index;
                expression     = new RegexExpression(buffer);
                CheckClosingParen(buffer);
                return(true);
            }
            return(false);
        }
Example #5
0
        bool CheckOptions(RegexBuffer buffer)
        {
            // look for ?imnsx-imnsx:
            Regex regex = new Regex(@"
				        ^                         # anchor to start of string
						\?(?<Options>[imnsx-]+):
						"                        ,
                                    RegexOptions.IgnorePatternWhitespace);

            Match match = regex.Match(buffer.String);

            if (match.Success)
            {
                string option = match.Groups["Options"].Value;
                description = String.Format("Set options to {0}",
                                            optionNames[option]);
                expression     = null;
                buffer.Offset += match.Groups[0].Length;
                return(true);
            }
            return(false);
        }
Example #6
0
        bool CheckNonBacktracking(RegexBuffer buffer)
        {
            // Look for non-backtracking sub-expression ?>

            Regex regex = new Regex(@"
				        ^                         # anchor to start of string
						\?\>
						(?<Rest>.+)             # The rest of the expression
						"                        ,
                                    RegexOptions.IgnorePatternWhitespace);
            Match match = regex.Match(buffer.String);

            if (match.Success)
            {
                description = String.Format("Non-backtracking subexpression");

                buffer.Offset += match.Groups["Rest"].Index;
                expression     = new RegexExpression(buffer);

                this.CheckClosingParen(buffer);
                return(true);
            }
            return(false);
        }