![](/img/trans.png)
[英]Find a string surrounded by square brackets and *not* prefaced with a specific character
[英]Regex to find single word surrounded by square brackets
我對以下正則表達式問題感到困惑。
我正在嘗試找到被方括號括起來且沒有空格的單詞。 像這樣:
[singleWord]
我不想找到這樣的短語
[a series of words]
目前,我正在使用此正則表達式:
/\[(.*?)\]/g
它正在尋找單詞和短語。 誰能建議如何修改它,使其只能在方括號中找到沒有空格的單詞?
謝謝!!
嘗試替換.*?
在您的正則表達式中使用\\S*
。 .
將匹配包括空格在內的任何字符,而\\S
僅匹配非空格字符
/\[(\S*)\]/g
I'm trying to find single words surrounded by square brackets without spaces.
您可以使用此正則表達式:
/\[([^\s\]]*)\]/g
您當前的正則表達式允許任何操作。 你只想要字母。
/\[([a-z])\]/gi
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.