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); }
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); }
public void AddLookup(RegexItem item, int startLocation, int endLocation, bool canCoalesce) { if (inSeries) { // in a series, add character to the previous one... if (canCoalesce) { RegexRef lastItem = (RegexRef)expressionLookup[expressionLookup.Count - 1]; lastItem.StringValue += item.ToString(0); lastItem.Length += endLocation - startLocation + 1; } else { expressionLookup.Add(new RegexRef(item, startLocation, endLocation)); inSeries = false; } } else { if (canCoalesce) { inSeries = true; } expressionLookup.Add(new RegexRef(item, startLocation, endLocation)); } }
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); }
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); }
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); }
bool CheckConditional(RegexBuffer buffer) { // Look for conditional (?(name)yesmatch|nomatch) // (name can also be an 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("Conditional Subexpression"); buffer.Offset += match.Groups["Rest"].Index; expression = new RegexConditional(buffer); return(true); } return(false); }
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 subexpressio"); buffer.Offset += match.Groups["Rest"].Index; expression = new RegexExpression(buffer); this.CheckClosingParen(buffer); return(true); } return(false); }
public RegexRef(RegexItem regexItem, int start, int end) { stringValue = regexItem.ToString(0); this.start = start; this.end = end; }
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; }
bool CheckConditional(RegexBuffer buffer) { // Look for conditional (?(name)yesmatch|nomatch) // (name can also be an 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("Conditional Subexpression"); buffer.Offset += match.Groups["Rest"].Index; expression = new RegexConditional(buffer); return true; } return false; }
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; }
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; }
public RegexRef(RegexItem regexItem, int start, int end) { stringValue = regexItem.ToString(0); this.start = start; this.end = end; }
bool CheckNonCapturing(RegexBuffer buffer) { // Look for non-capturing ?: 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-capturing Group"); buffer.Offset += match.Groups["Rest"].Index; expression = new RegexExpression(buffer); this.CheckClosingParen(buffer); return true; } return false; }
public void AddLookup(RegexItem item, int startLocation, int endLocation, bool canCoalesce) { if (inSeries) { // in a series, add character to the previous one... if (canCoalesce) { RegexRef lastItem = (RegexRef) expressionLookup[expressionLookup.Count - 1]; lastItem.StringValue += item.ToString(0); lastItem.Length += endLocation - startLocation + 1; } else { expressionLookup.Add(new RegexRef(item, startLocation, endLocation)); inSeries = false; } } else { if (canCoalesce) { inSeries = true; } expressionLookup.Add(new RegexRef(item, startLocation, endLocation)); } }
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; }
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; }
public void AddLookup(RegexItem item, int startLocation, int endLocation) { AddLookup(item, startLocation, endLocation, false); }
public void AddLookup(RegexItem item, int startLocation, int endLocation) { AddLookup(item, startLocation, endLocation, false); }