Ejemplo n.º 1
0
 /// <summary>
 /// Generates a negative character range expression ("[^a-z]") with the specified start/end characters.
 /// </summary>
 /// <param name="rangeStart">First character in the range.</param>
 /// <param name="rangeEnd">Last character in the range.</param>
 /// <param name="useCharacterCodes">True - encode every character with "\uNNNN" pattern. False - use every character explicitly.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the character range.</returns>
 public static RegexNodeCharacterRange NegativeCharacterRange(char rangeStart, char rangeEnd, bool useCharacterCodes, RegexQuantifier quantifier)
 {
     return new RegexNodeCharacterRange(rangeStart, rangeEnd, true) { Quantifier = quantifier, UseCharacterCodes = useCharacterCodes };
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Generates a negative character range expression ("[^a-z]") with the specified start/end characters.
 /// </summary>
 /// <param name="rangeStart">First character in the range.</param>
 /// <param name="rangeEnd">Last character in the range.</param>
 /// <param name="useCharacterCodes">True - encode every character with "\uNNNN" pattern. False - use every character explicitly.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the character range.</returns>
 public static RegexNodeCharacterRange NegativeCharacterRange(char rangeStart, char rangeEnd, bool useCharacterCodes, RegexQuantifier quantifier)
 {
     return(new RegexNodeCharacterRange(rangeStart, rangeEnd, true)
     {
         Quantifier = quantifier, UseCharacterCodes = useCharacterCodes
     });
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Generates a Regex metacharacter, such as \d, \w or \s. Many metacharacter constants are available in RegexMetaChars class.
 /// </summary>
 /// <param name="characterPattern">Metacharacter pattern.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the specified metacharacter.</returns>
 public static RegexNodeLiteral MetaCharacter(string characterPattern, RegexQuantifier quantifier)
 {
     return new RegexNodeLiteral(characterPattern) { Quantifier = quantifier };
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Generates a zero-width positive lookbehind assertion ("(?&lt;=lookbehind)match").
 /// </summary>
 /// <param name="lookupExpression">Lookbehind expression.</param>
 /// <param name="matchExpression">Match expression.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the positive lookbehind assertion.</returns>
 public static RegexNodeLookAround PositiveLookBehind(RegexNode lookupExpression, RegexNode matchExpression, RegexQuantifier quantifier)
 {
     return new RegexNodeLookAround(RegexLookAround.PositiveLookBehind, lookupExpression, matchExpression) { Quantifier = quantifier };
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Generates an ASCII character pattern ("\xNN") with the specified character code.
 /// </summary>
 /// <param name="code">ASCII character code.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the specified ASCII character.</returns>
 public static RegexNodeLiteral AsciiCharacter(byte code, RegexQuantifier quantifier)
 {
     return new RegexNodeLiteral(string.Format(CultureInfo.InvariantCulture, "\\x{0:x2}", code & 0xFF)) { Quantifier = quantifier };
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Generates an alternation expression with two or more options ("a|b|c|...").
 /// </summary>
 /// <param name="expressions">Array of option expressions.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the alternation expression.</returns>
 public static RegexNodeAlternation Alternate(RegexNode[] expressions, RegexQuantifier quantifier)
 {
     return new RegexNodeAlternation(expressions) { Quantifier = quantifier };
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Generates a non-capturing group with the specified subexpression.
 /// </summary>
 /// <param name="matchExpression">Inner expression.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the non-capturing group.</returns>
 public static RegexNodeGroup NonCapturingGroup(RegexNode matchExpression, RegexQuantifier quantifier)
 {
     return new RegexNodeGroup(matchExpression, false) { Quantifier = quantifier };
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Generates an alternation expression with two options ("a|b").
 /// </summary>
 /// <param name="expression1">First option.</param>
 /// <param name="expression2">Second option.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the alternation expression.</returns>
 public static RegexNodeAlternation Alternate(RegexNode expression1, RegexNode expression2, RegexQuantifier quantifier)
 {
     return new RegexNodeAlternation(expression1, expression2) { Quantifier = quantifier };
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Generates a conditional match expression ("(?(condition)|(true)|(false))").
 /// </summary>
 /// <param name="conditionExpression">Condition expression.</param>
 /// <param name="trueMatchExpression">True match expression.</param>
 /// <param name="falseMatchExpression">False match expression.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the conditional match expression.</returns>
 public static RegexNodeConditionalMatch ConditionalMatch(RegexNode conditionExpression, RegexNode trueMatchExpression, RegexNode falseMatchExpression, RegexQuantifier quantifier)
 {
     return new RegexNodeConditionalMatch(conditionExpression, trueMatchExpression, falseMatchExpression) { Quantifier = quantifier };
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Generates a character set expression ("[abc]") using a preformatted character string.
 /// </summary>
 /// <param name="characters">Character set description. Special characters will be automatically escaped.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the character set.</returns>
 public static RegexNodeCharacterSet CharacterSet(string characters, RegexQuantifier quantifier)
 {
     return new RegexNodeCharacterSet(characters, false) { Quantifier = quantifier };
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Concatenates four nodes.
 /// </summary>
 /// <param name="node1">First node.</param>
 /// <param name="node2">Second node.</param>
 /// <param name="node3">Third node.</param>
 /// <param name="node4">Fourth node.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode representing the concatenation of child nodes.</returns>
 public static RegexNodeConcatenation Concatenate(RegexNode node1, RegexNode node2, RegexNode node3, RegexNode node4, RegexQuantifier quantifier)
 {
     return Concatenate(new[] { node1, node2, node3, node4 }, quantifier);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Generates a named capturing group with the specified subexpression.
 /// </summary>
 /// <param name="groupName">Group name.</param>
 /// <param name="matchExpression">Inner expression.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the named capturing group.</returns>
 public static RegexNodeGroup Group(string groupName, RegexNode matchExpression, RegexQuantifier quantifier)
 {
     return(new RegexNodeGroup(matchExpression, groupName)
     {
         Quantifier = quantifier
     });
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Generates a zero-width negative lookbehind assertion ("(?&lt;!lookbehind)match").
 /// </summary>
 /// <param name="lookupExpression">Lookbehind expression.</param>
 /// <param name="matchExpression">Match expression.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the negative lookbehind assertion.</returns>
 public static RegexNodeLookAround NegativeLookBehind(RegexNode lookupExpression, RegexNode matchExpression, RegexQuantifier quantifier)
 {
     return(new RegexNodeLookAround(RegexLookAround.NegativeLookBehind, lookupExpression, matchExpression)
     {
         Quantifier = quantifier
     });
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Generates a zero-width positive lookahead assertion ("match(?=lookahead)").
 /// </summary>
 /// <param name="lookupExpression">Lookahead expression.</param>
 /// <param name="matchExpression">Match expression.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the positive lookahead assertion.</returns>
 public static RegexNodeLookAround PositiveLookAhead(RegexNode lookupExpression, RegexNode matchExpression, RegexQuantifier quantifier)
 {
     return(new RegexNodeLookAround(RegexLookAround.PositiveLookAhead, lookupExpression, matchExpression)
     {
         Quantifier = quantifier
     });
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Generates a negative character set expression ("[^abc]") using a preformatted character string.
 /// </summary>
 /// <param name="characters">Character set description. Special characters will be automatically escaped.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the character set.</returns>
 public static RegexNodeCharacterSet NegativeCharacterSet(string characters, RegexQuantifier quantifier)
 {
     return new RegexNodeCharacterSet(characters, true) { Quantifier = quantifier };
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Generates a conditional match expression which uses a named group for condition evaluation ("(?(GroupName)|(true)|(false))").
 /// </summary>
 /// <param name="conditionGroupName">The name of the group to be used as a condition.</param>
 /// <param name="trueMatchExpression">True match expression.</param>
 /// <param name="falseMatchExpression">False match expression.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the conditional match expression.</returns>
 public static RegexNodeConditionalMatch ConditionalMatch(string conditionGroupName, RegexNode trueMatchExpression, RegexNode falseMatchExpression, RegexQuantifier quantifier)
 {
     return new RegexNodeConditionalMatch(conditionGroupName, trueMatchExpression, falseMatchExpression) { Quantifier = quantifier };
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Generates a negative character set expression ("[^abc]") from the specified character array.
 /// </summary>
 /// <param name="characters">An array of allowed characters.</param>
 /// <param name="useCharacterCodes">True - encode every character with "\uNNNN" pattern. False - use every character explicitly.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns></returns>
 public static RegexNodeCharacterSet NegativeCharacterSet(char[] characters, bool useCharacterCodes, RegexQuantifier quantifier)
 {
     return new RegexNodeCharacterSet(characters, true) { Quantifier = quantifier, UseCharacterCodes = useCharacterCodes };
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Generates an unnamed capturing group with the specified subexpression.
 /// </summary>
 /// <param name="matchExpression">Inner expression.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the unnamed capturing group.</returns>
 public static RegexNodeGroup Group(RegexNode matchExpression, RegexQuantifier quantifier)
 {
     return new RegexNodeGroup(matchExpression) { Quantifier = quantifier };
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Generates a zero-width negative lookahead assertion ("match(?!lookahead)").
 /// </summary>
 /// <param name="lookupExpression">Lookahead expression.</param>
 /// <param name="matchExpression">Match expression.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the negative lookahead assertion.</returns>
 public static RegexNodeLookAround NegativeLookAhead(RegexNode lookupExpression, RegexNode matchExpression, RegexQuantifier quantifier)
 {
     return new RegexNodeLookAround(RegexLookAround.NegativeLookAhead, lookupExpression, matchExpression) { Quantifier = quantifier };
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Generates a named capturing group with the specified subexpression.
 /// </summary>
 /// <param name="groupName">Group name.</param>
 /// <param name="matchExpression">Inner expression.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the named capturing group.</returns>
 public static RegexNodeGroup Group(string groupName, RegexNode matchExpression, RegexQuantifier quantifier)
 {
     return new RegexNodeGroup(matchExpression, groupName) { Quantifier = quantifier };
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Generates a simple string literal "as is", without character escaping. This method can be used to render
 /// explicit preformatted patterns of the Regex or some rare constructions not supported by RegexBuilder.
 /// </summary>
 /// <param name="value">Node text.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the specified text.</returns>
 public static RegexNodeLiteral NonEscapedLiteral(string value, RegexQuantifier quantifier)
 {
     return new RegexNodeLiteral(value) { Quantifier = quantifier };
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Generates a backreference to the group with the specified index ("\N").
 /// </summary>
 /// <param name="groupIndex">Group ordinal number.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the group reference.</returns>
 public static RegexNodeGroupReference GroupBackReference(int groupIndex, RegexQuantifier quantifier)
 {
     return new RegexNodeGroupReference(groupIndex) { Quantifier = quantifier };
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Generates a Unicode character pattern ("\uNNNN") with the specified character code.
 /// </summary>
 /// <param name="code">Unicode character code.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the specified Unicode character.</returns>
 public static RegexNodeLiteral UnicodeCharacter(int code, RegexQuantifier quantifier)
 {
     return new RegexNodeLiteral(string.Format(CultureInfo.InvariantCulture, "\\u{0:x4}", code)) { Quantifier = quantifier };
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Generates a backreference to a named group ("\k&lt;GroupName&gt;").
 /// </summary>
 /// <param name="groupName">Group name.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the group reference.</returns>
 public static RegexNodeGroupReference GroupBackReference(string groupName, RegexQuantifier quantifier)
 {
     return new RegexNodeGroupReference(groupName) { Quantifier = quantifier };
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Generates a subexpression with disabled backtracking ("(?&gt;expression)").
 /// </summary>
 /// <param name="innerExpression">Inner expression.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns>An instance of RegexNode containing the expression with suppressed backtracking.</returns>
 public static RegexNodeBacktrackingSuppression BacktrackingSuppression(RegexNode innerExpression, RegexQuantifier quantifier)
 {
     return new RegexNodeBacktrackingSuppression(innerExpression) { Quantifier = quantifier };
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Generates a negative character set expression ("[^abc]") from the specified character array.
 /// </summary>
 /// <param name="characters">An array of allowed characters.</param>
 /// <param name="useCharacterCodes">True - encode every character with "\uNNNN" pattern. False - use every character explicitly.</param>
 /// <param name="quantifier">Node quantifier.</param>
 /// <returns></returns>
 public static RegexNodeCharacterSet NegativeCharacterSet(char[] characters, bool useCharacterCodes, RegexQuantifier quantifier)
 {
     return(new RegexNodeCharacterSet(characters, true)
     {
         Quantifier = quantifier, UseCharacterCodes = useCharacterCodes
     });
 }