RegEx Starts with [ and ending with ]

前端 未结 4 1810
广开言路
广开言路 2020-12-10 02:43

What is the Regular Expression to find the strings starting with [ and ending with ]. Between [ and] all kind of character are fine.

4条回答
  •  无人及你
    2020-12-10 03:13

    [ and ] are special characters in regular expressions, so you need to escape them. This should work for you:

    \[.*?\]
    

    .*? does non-greedy matching of any character. The non-greedy aspect assures that you will match [abc] instead of [abc]def]. Add a leading ^ and trailing $ if you want to match the entire string, e.g. no match at all in abc[def]ghi.

提交回复
热议问题