括号中匹配单词前面表达式的Regex lookbehind

括号中匹配单词前面表达式的Regex lookbehind,regex,lookbehind,Regex,Lookbehind,是否可以使用Regex lookback表达式来匹配all方括号中任何内容前面的单词,匹配本例中的单词concertetur和libero Lorem ipsum Door sit amet,奉献[告别]精英。这是一个很好的例子。自以为是的知识。轻率的同侧脸。这是一种自由的饮食 我想从词条内容中划出MS Word中的词典词条。条目后面是方括号中的拼音,一旦这样选择,我会增加它们的字体,从而使它们与文本的其余部分区分开来,并与内容分隔开来 编辑:Kent给出的表达式与一个单词条目完美匹配,例如:

是否可以使用Regex lookback表达式来匹配all方括号中任何内容前面的单词,匹配本例中的单词concerteturlibero

Lorem ipsum Door sit amet,奉献[告别]精英。这是一个很好的例子。自以为是的知识。轻率的同侧脸。这是一种自由的饮食

我想从词条内容中划出MS Word中的词典词条。条目后面是方括号中的拼音,一旦这样选择,我会增加它们的字体,从而使它们与文本的其余部分区分开来,并与内容分隔开来

编辑:Kent给出的表达式与一个单词条目完美匹配,例如:

沸腾的,沸腾的【例】1。vreo、uzavreo、kipući 2。乌兹鲁詹拉扎伦

带有连字符的两个单词条目,例如:

沸点[boilin point]s vrelište

但是短语动词的第一个单词和其他两个单词词条被省略了,这意味着在词条中,例如:

用螺栓固定,固定【例】isključiti;伊兹拉努蒂

这场比赛是出局的,而不是出局的,因为我需要它

因为这是一个字典,我可以分别为每个字母范围应用正则表达式,如果我有一个正则表达式,它将搜索以括号前面的特定字母开头的第一个单词,匹配该单词和后面的单词,我就能够解决这个问题。对于我的示例中的“B”条目,这意味着表达式将匹配以字母B开头的单个单词,将两个单词条目连字符为沸点,并匹配短语动词中的“bolt”,如“bolt out”以及其后的介词,即“out”在这种情况下

在我的字典里,可能只有很少的两个单词条目,如果有的话,这些条目中的单词都是以同一个字母开头的,我真的能忍受这么小的误差

EDIT2:我将段落分隔符放在方括号之前,现在我的条目位于前一行的末尾,如下所示:

[aidwulf]的zool vrsta hijene(Proteles cristata)阿隆的胡子

[earanzrod]的bot divizma(Ver-bascum Thapsus)阿巴卡

[a'baid'on]vi biti na pomoći,stajati uz bok遵守

Aaron's beard是以方括号开始的第二行条目,Abacca是以方括号开始的第三行条目,依此类推

为了解决我的问题,我需要两个正则表达式。首先,我需要一个正则表达式来匹配以Aa开头的单词中的每个字母Aa,并且只匹配每行最后一个字母之前的单词。在我的示例中,在第一个示例中与Aaron的A匹配,在第三个示例中与Aaron的A匹配。然后我会用星号替换这封信,以得到*罗恩的胡子*和*等待

第二个正则表达式将匹配每一行中的最后一个单词(包括连字符两个单词复合词)以及以我之前创建的星号开头的单词


谢谢您的帮助。

您需要向前看,而不是向后看:

\w+(?=\s*\[[^]])
使用grep进行测试:

kent$  echo "Lorem ipsum dolor sit amet, consectetur [adipiscing] elit. Nunc eu tellus vel nunc pretium lacinia. Proin sed lorem. Cras sed ipsum. Nunc a libero [quis] risus sollicitudin imperdiet."|grep -Po '\w+(?=\s*\[[^\]])'
consectetur
libero
kent$  cat file
boiling ['boilin] adj 1. vreo, uzavreo, kipući 2. razjaren, uzrujan
with hyphenated two-word entries such as:
boiling-point ['boilin point] s vrelište
but the first word of phrasal verbs and other two-word entries is left out, which means that in the entries such as:
bolt out ['bault'aut] vt isključiti; izlanuti

kent$  grep -oP '[bB].+?(?=\s*\[[^]])' file
boiling
boiling-point
bolt out
编辑

试试这个正则表达式:

[bB].+?(?=\s*\[[^]])
仍然使用grep进行测试:

kent$  echo "Lorem ipsum dolor sit amet, consectetur [adipiscing] elit. Nunc eu tellus vel nunc pretium lacinia. Proin sed lorem. Cras sed ipsum. Nunc a libero [quis] risus sollicitudin imperdiet."|grep -Po '\w+(?=\s*\[[^\]])'
consectetur
libero
kent$  cat file
boiling ['boilin] adj 1. vreo, uzavreo, kipući 2. razjaren, uzrujan
with hyphenated two-word entries such as:
boiling-point ['boilin point] s vrelište
but the first word of phrasal verbs and other two-word entries is left out, which means that in the entries such as:
bolt out ['bault'aut] vt isključiti; izlanuti

kent$  grep -oP '[bB].+?(?=\s*\[[^]])' file
boiling
boiling-point
bolt out

你需要向前看,而不是向后看:

\w+(?=\s*\[[^]])
使用grep进行测试:

kent$  echo "Lorem ipsum dolor sit amet, consectetur [adipiscing] elit. Nunc eu tellus vel nunc pretium lacinia. Proin sed lorem. Cras sed ipsum. Nunc a libero [quis] risus sollicitudin imperdiet."|grep -Po '\w+(?=\s*\[[^\]])'
consectetur
libero
kent$  cat file
boiling ['boilin] adj 1. vreo, uzavreo, kipući 2. razjaren, uzrujan
with hyphenated two-word entries such as:
boiling-point ['boilin point] s vrelište
but the first word of phrasal verbs and other two-word entries is left out, which means that in the entries such as:
bolt out ['bault'aut] vt isključiti; izlanuti

kent$  grep -oP '[bB].+?(?=\s*\[[^]])' file
boiling
boiling-point
bolt out
编辑

试试这个正则表达式:

[bB].+?(?=\s*\[[^]])
仍然使用grep进行测试:

kent$  echo "Lorem ipsum dolor sit amet, consectetur [adipiscing] elit. Nunc eu tellus vel nunc pretium lacinia. Proin sed lorem. Cras sed ipsum. Nunc a libero [quis] risus sollicitudin imperdiet."|grep -Po '\w+(?=\s*\[[^\]])'
consectetur
libero
kent$  cat file
boiling ['boilin] adj 1. vreo, uzavreo, kipući 2. razjaren, uzrujan
with hyphenated two-word entries such as:
boiling-point ['boilin point] s vrelište
but the first word of phrasal verbs and other two-word entries is left out, which means that in the entries such as:
bolt out ['bault'aut] vt isključiti; izlanuti

kent$  grep -oP '[bB].+?(?=\s*\[[^]])' file
boiling
boiling-point
bolt out

请扩展你的例子。将字符串与正则表达式匹配后,您希望得到什么样的结果?到目前为止,您使用的表达式看起来如何?你想匹配括号吗?哪种理解是正确的?1) 你想从行首到第一个
[foo]
2)你想从第一个
b/b
到第一个
[foo]
?2)是我要找的肯特,我想从第一个匹配(最靠近括号)以字母B开头直到第一个方括号的单词。请扩展您的示例。将字符串与正则表达式匹配后,您希望得到什么样的结果?到目前为止,您使用的表达式看起来如何?你想匹配括号吗?哪种理解是正确的?1) 你想从一行开始匹配到第一个
[foo]
2)你想从第一个
b/b
匹配到第一个
[foo]
?2)是我要找的肯特,我想从第一个(最靠近括号的)单词开始匹配到第一个方括号。谢谢你,肯特,它的工作原理就像一个单字条目的魅力!此表达式是否可能包含由连字符分隔的多个单词条目,例如匹配中的“criss cross”?请尝试将
\w
更改为
[\w-]
,现在它已经百分之百地完美了:)非常感谢Kent!我没有意识到很多条目都是短语动词和类似的两个单词条目Kent,现在我有一个问题。括号前面的条目是粗体格式的,你能给出一个表达式来捕捉括号之前粗体的内容吗?@TotoKalvera regex可以匹配文本,但不能处理样式。。。正则表达式不能匹配粗体、斜体。。。font size=n等。非常感谢你,肯特,它就像一个单字输入的符咒!此表达式是否可能包含由连字符分隔的多个单词条目,如匹配中的“criss cross”?请尝试将
\w
更改为
[\w-]
,现在它已经百分之百地完美了:)谢谢