Is there any way to convert the following BNF into a .Net regex? (I'm not stuck on the BNF, but I thought it might be the best way to explain what I was trying to do)
<field> ::= "<<" <fieldname> <options> ">>"
<options> ::= "" | "(" <option> ")"
<option> ::= "" |
<option> <non-paren> |
<option> <escaped-character>
<escaped-character> ::= "\\" | "\)"
<non-paren> ::= any character but paren
<fieldname> ::= any string that doesn't contain "(" or ">>"
I'm close, but I can't figure out how to deal with escaping "\" and ")". This captures the fieldname and option in named groups.
<<(?<fieldname>.\*?)(\((?<option>.*?)\))?>>
Edit
It turns out that I was rustier at BNFs than I thought.
What I was trying to get at is that parens are special characters. Inside the "option" section, they must be escaped by a slash. (And slashes must also be escaped).