我想把一个字符串开头和结尾的方括号去掉,如果它们存在的话。
[Just a string]
Just a string
Just a string [comment]
[Just a string [comment]]
应该得到以下结果
Just a string
Just a string
Just a string [comment]
Just a string [comment]
我尝试构建一个正则表达式,但是我没有正确地理解它,因为它没有查找位置:
string.replace(/[\[\]]+/g,'')
[只是一个字符串[注释]
? - Wiktor Stribiżew^
和$
锚点。 - Matt BurlandJust a string [comment
。 - user3142695string.replace(/^\[|]$/g, '')
。 - bobble bubble