I would like to extract characters between first opening and last closing brackets in a string like match[input[name="firstname"]] considering the characters to retrieve may also contain more brackets. In this case it would get input[name="firstname"] Also, the string may contain some special characters like { # / \ ^
I would like to extract characters between first opening and last closing brackets in
Share
This somehow awkward-looking regular expression
basically says “no brackets, then [, then no brackets, then ]”.
To make this slightly more useful, here’s how to extract topmost brackets’ content from a string with respect to nesting:
Recursive matches support in a regex engine would allow to write that in one line, but javascript re’s are not that advanced.