我想从字符串的开头和结尾删除方括号,如果它们存在的话.
[Just a string]
Just a string
Just a string [comment]
[Just a string [comment]]
Run Code Online (Sandbox Code Playgroud)
应该导致
Just a string
Just a string
Just a string [comment]
Just a string [comment]
Run Code Online (Sandbox Code Playgroud)
我试图建立一个正则表达式,但我没有以正确的方式得到它,因为它不寻找位置:
string.replace(/[\[\]]+/g,'')
Run Code Online (Sandbox Code Playgroud)
string.replace(/^\[(.+)\]$/,'$1')
Run Code Online (Sandbox Code Playgroud)
应该做的伎俩.
^ 匹配字符串的开头$ 匹配字符串的结尾.(.+) 匹配其间的所有内容,在最终字符串中报告.| 归档时间: |
|
| 查看次数: |
5295 次 |
| 最近记录: |