gpt4 book ai didi

regex - 正则表达式匹配,在一个句子中,括号内的词

转载 作者:行者123 更新时间:2023-12-02 05:21:33 31 4
gpt4 key购买 nike

我需要一个正则表达式来匹配句子中括号内的单词。例如:

"this is [stack]overflow. I [[love]this[website]]."

我想从上面的句子中匹配单词 stack、love 和 website。

我已经尝试了以下正则表达式 \[(.*[^\]\[])\] 但它不起作用。

最佳答案

以下应该有效:

\[([^\[\]]*)\]

示例:http://www.rubular.com/r/uJ0sOtdcgF

解释:

\[           # match a literal '['
( # start a capturing group
[^\[\]]* # match any number of characters that are not '[' or ']'
) # end of capturing group
\] # match a literal ']'

关于regex - 正则表达式匹配,在一个句子中,括号内的词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13769022/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com