I would like to know how I could transform the given string into the specified array:
String
all ("hi there \(option\)", (this, that), other) another
Result wanted (Array)
[0] => all,
[1] => Array(
[0] => "hi there \(option\)",
[1] => Array(
[0] => this,
[1] => that
),
[2] => other
),
[2] => another
This is used for a kind of console that I’m making on PHP.
I tried to use preg_match_all but, I don’t know how I could find parentheses inside parentheses in order to “make arrays inside arrays”.
EDIT
All other characters that are not specified on the example should be treated as String.
EDIT 2
I forgot to mention that all parameter’s outside the parentheses should be detected by the space character.
There’s no question that you should write parser if you are building syntax tree. But if you just need to parse this sample input
regexstill might be a tool:Demo.
Note: If input will be malformed regex will definitely fail. I am writing this solution just in a case you need fast script. Writing lexer and parser is time-consuming work, that will need lots of research.