Regular expression to match brackets

后端 未结 4 1506
清酒与你
清酒与你 2021-01-04 11:37

For a templating engine, I am using regular expressions to identify content under brackets in a string. For example the regex needs to match {key} or or [element

4条回答
  •  清歌不尽
    2021-01-04 12:19

    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...

提交回复
热议问题