Your task is to create a program that determines whether a given string is a valid regular expression or not using code snippets sourced from sites on the StackExchange network.
For the purposes of this challenge, the regular expression dialect will be a stripped down and mostly minimal set of meta-characters:
()*?|\. As such, you will not be able to use built-in regex parsers.
\is used to escape meta-characters. It must be followed by a meta-character.
- Unescaped parentheses must be balanced
?must be preceded by either a non-meta-character, a parenthesized group, or an escaped meta-character.
- All other printable ASCII characters plus newline, tab, and space must be supported as non-meta characters. What happens with a string containing other characters is undefined.
- The actual meaning of the regex is not important for this challenge.
Truthy: abc a? (a|)* () a|b* \* \\ \\* a*b?(cd|e) + [ } (123\))* \| (a(b(c|d)*e)*f)* (|\)*) (abc)+* (abc)+ +abc ^ last test case is an actual newline Falsy: ?abc * ** \ ( a*? a?* ? a) (\) (|\)* \() |* (?:abc) \\** \n
Your overall score is the number of snippets taken from questions and answers around StackExchange.
- Repeated snippets count for as many times as they are used.
- Whitespace can be added and removed freely (because of Python, Haskell, and other whitespace-sensitive languages) and does not count toward your snippet count.
- The exception would be if your code is actually written in Whitespace.
- Snippets are allowed from any StackExchange site as long as they come from questions, answers, and comments that are older (Including by edit time - use older revisions if necessary) than this challenge. (Sep 24, 2019 @ 3:30 PM UTC)
- Snippets can come from anywhere in a question, answer, or comment body, whether it's in a preformatted code block or not.
- Splicing a snippet into the middle of another causes the outer snippet to count as two snippets
Lowest score wins!