这个
^
和
$
锚需要整个字符串与模式匹配
[\s\S]+
尽可能多地匹配任何1个以上的字符,抓住任何
[
和
]
在去字符串末尾的路上,所以最后
]
将匹配最右边的
]
在字符串中。
您可以使用以下正则表达式:
r'\[\d{2}_[^]]+]'
请参见
regex demo
细节
-
\[
-文字
[
-
\d{2}
-两位数
-
_
-下划线
-
[^]]+
-一个或多个字符,而不是
]
-
]
-文字
]
.
请参见
Python demo
:
import re
s='''C: state name of the Company in Russian: [03_SNYuLOOO IC "Story Group".]
). - [04_MNMestablishment of the Company: 107S64, Russian Federation, Moscow,
ul. Krasnobogatyrskaya, 2, is built.
2, floor 3. com. 11. Office B].'''
print(re.findall(r'\[\d{2}_[^]]+]', s))
# => ['[03_SNYuLOOO IC "Story Group".]', '[04_MNMestablishment of the Company: 107S64, Russian Federation, Moscow, \nul. Krasnobogatyrskaya, 2, is built.\n2, floor 3. com. 11. Office B]']