Input is a string representing a list of items.
The list is defined as open curly { , followed by 0 or more elements separated by spaces, followed by a closed curly } .
An element is either a literal or a list of elements.
A literal is a sequence of characters without spaces. If an element contains curly braces, it must be escaped with a backslash: \{ and \} . (Or you could assume that curls are not allowed inside literals, for simplicity)
Example:
"{abc { def ghi } 7 { 1 {2} {3 4} } {5 6} x\{yz \}foo }"
There are no curls in literals:
"{abc { def ghi } 7 { 1 {2} {3 4} } {5 6} xyz foo }"
(This is a simplified definition of a Tcl list.)
What I want to know: can the input be split into elements of the outermost loop using a regular expression?
Expected Result:
abc { def ghi } 7 { 1 {2} {3 4} } {5 6} x{yz }foo
The real question is: can this be done using regular expression?
I'm most interested in the taste of .NET, but it will accept any answers.
I will send my own guess in response and see if it is checked or destroyed.
source share