Remove text between square brackets at the end of string

前端 未结 3 1411
傲寒
傲寒 2021-01-24 03:39

I need a regex to remove last expression between brackets (also with brackets)

source: input[something][something2] target: input[something]

I\'ve tried this, bu

3条回答
  •  囚心锁ツ
    2021-01-24 04:11

    Do not use the g modifier, and use the $ anchor:

    "input[something][something2]".replace(/\[[^\]]*\]$/, '');
    

提交回复
热议问题