Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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,我有下面的文本块 Word1 Word2 Word3 Word4 [Hello world Word1] 我需要一个正则表达式来查找括号外的Word1,但不能在括号内使用正则表达式可以这样做吗 感谢Rob这个问题提出了一些关于括号嵌套的问题。我可以编写一个在[…][…][…][…]上运行的正则表达式,但是[[[]]][]]呢?我不知道您使用的是什么语言,但如果它支持递归正则表达式,请使用以下命令:/\[([^[]|(?R))*?\]/。您需要删除与此正则表达式匹配的任何内容,然后使用标

我有下面的文本块

Word1 
Word2 
Word3 
Word4 [Hello world Word1] 
我需要一个正则表达式来查找括号外的Word1,但不能在括号内使用正则表达式可以这样做吗


感谢Rob

这个问题提出了一些关于括号嵌套的问题。我可以编写一个在
[…][…][…][…]
上运行的正则表达式,但是
[[[]]][]]
呢?我不知道您使用的是什么语言,但如果它支持递归正则表达式,请使用以下命令:
/\[([^[]|(?R))*?\]/
。您需要删除与此正则表达式匹配的任何内容,然后使用标准搜索函数搜索所需的单词

正则表达式解释:

\[       // opening bracket
  (      // start group
  [^[]   // any character, but not opening bracket
  |      // or
  (?R)   // another nested bracket group
  )*?     // zero or more of this group, lazy
\]       // closing bracket
例如:


我们没有递归reg-ex和im使用MS WORD通配符:(-我如何在括号外找到特定的单词,而不是所有单词