开发者

Removing words inside brackets with regex

I want to remove words inside bracket, I'm currently using this

【.*】

【remove this】preserve this 【remove this】

but it removes everything for this because there is another bracket

How can I solve this? it also happens on开发者_开发技巧 comma

◆.*、

◆ remove this、preserve this、

that regex removes everything because I have 2 commas


Use non-greedy matching with ?, and also escape the brackets, which are special characters:

\[.*?\]


You can try two solutions:

  • Lazy Operators (this might not work on your RegEx parser)

    \[.*?\]
    
    .*?,
    
  • Or replace . by a negation list to match any element but the end delimiter:

    \[[^]]*\]
    
    [^,]*,
    


use a specified character group

\[[^\]]+\]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜