Regular expression to match brackets

you could use alternatives using pipe character (|) like this one /\[([\s\S]+?)\]|\{([\s\S]+?)\}|<([\s\S]+?)>/, although it gets pretty long.

EDIT: shortend the regex, is not that long any more...


var rx = /\[[^\]]+\]|\{[^}]+\}|<[^>]+>/;

The best way to do this, especially if different brackets can have different meanings, is to split into 3 regular expressions:

var rx1 = /\[([^\]]+)]/;
var rx2 = /\(([^)]+)\)/;
var rx3 = /{([^}]+)}/;

These will match any text surrounded by [], (), and {} respectively, with the text inside in the first matched group.