Can you select text between two matching parentheses in regex?
If you want to select text between two matching parentheses, you are out of luck with regular expressions. This is impossible (*). This regex just returns the text between the first opening and the last closing parentheses in your string. (*) Unless your regex engine has features like balancing groups or recursion.
Do you need regular expressions to match nested brackets?
The answer depends on whether you need to match matching sets of brackets, or merely the first open to the last close in the input text. If you need to match matching nested brackets, then you need something more than regular expressions. – see @dehmann You need to decide what your code needs to match in this case.
Can a regex return text between opening and closing parentheses?
This regex just returns the text between the first opening and the last closing parentheses in your string. (*) Unless your regex engine has features like balancing groups or recursion. The number of engines that support such features is slowly growing, but they are still not a commonly available.
How to use regex recursion to match brackets?
You can use regex recursion: [^\\ (]* matches everything that isn’t an opening bracket at the beginning of the string, (\\ (.*\\)) captures the required substring enclosed in brackets, and [^\\)]* matches everything that isn’t a closing bracket at the end of the string.
Are there any regular expressions that match brackets?
Note that this expression does not attempt to match brackets; a simple parser (see dehmann’s answer) would be more suitable for that. If you want to select text between two matching parentheses, you are out of luck with regular expressions. This is impossible (*).
Can you use a regular expression in regex?
(*) Unless your regex engine has features like balancing groups or recursion. The number of engines that support such features is slowly growing, but they are still not a commonly available. This answer explains the theoretical limitation of why regular expressions are not the right tool for this task.