Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 捕获包含特定单词的括号内的单词_Regex - Fatal编程技术网

Regex 捕获包含特定单词的括号内的单词

Regex 捕获包含特定单词的括号内的单词,regex,Regex,字符串: XT1941-4 [Type: M3B8A] [Support: NFC] XT1941-4 [Type: M3B8A] [Some exra word Support: Blueooth] 我只想捕获[支持:NFC]和[一些exra word支持:Blueooth] 我创建的正则表达式模式在捕获我不想要的[Type…]时给出了错误捕获 我有点困在这上面了,谢谢你的帮助 您可以使用否定的[^来匹配方括号之间的支持 \[^][]*\b支持\b[^][]*] 解释 \[匹配[ [^

字符串:

XT1941-4 [Type: M3B8A] [Support: NFC]

XT1941-4 [Type: M3B8A] [Some exra word Support: Blueooth]
我只想捕获
[支持:NFC]
[一些exra word支持:Blueooth]

我创建的正则表达式模式在捕获我不想要的
[Type…]
时给出了错误捕获

我有点困在这上面了,谢谢你的帮助

您可以使用否定的
[^
来匹配方括号之间的支持

\[^][]*\b支持\b[^][]*]
解释

  • \[
    匹配
    [
  • [^][]*
    匹配除
    [
    ]
  • \b支持\b
    匹配由单词边界包围的支持,以防止成为较大单词的一部分
  • [^][]*
    匹配除
    [
    ]
  • ]
    匹配
    ]

Omg你真快,你能简单解释一下这是怎么回事吗?@NubPro我已经添加了模式和部分的分解。嘿,第四只鸟,这似乎不适用于Javascript。我正在研究它,你需要避开
[
]
。最终正则表达式:
\[^[\]*\bSupport\b[^[\]*]]
XT1941-4 [Type: M3B8A] [Support: NFC]

XT1941-4 [Type: M3B8A] [Some exra word Support: Blueooth]