Created
November 19, 2015 20:06
-
-
Save anonymous/5fd424f46b9d878170d4 to your computer and use it in GitHub Desktop.
Balanced pattern matcher regular expression generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Match everything inside balancing groups ['<' and '>'] (Variables) and ['{' and '}'] (Macros) | |
// ex: <This is A Variable> and {This is a macro} | |
// http://goo.gl/Rjo6Ih | |
public static string PatternBuilder(char open, char close) | |
{ | |
return $"(((?<open>{open})[^{open}]*)+([^{open}]*(?<close-open>{close}))+).*?(?(open)(?!))"; | |
} | |
public static string caretPattern => PatternBuilder('<', '>'); | |
public static string bracePattern => PatternBuilder('{', '}'); | |
public static string parenthesisPattern => PatternBuilder('(', ')'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment