Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.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,我正在努力找到一个正则表达式,它可以找到任何用方括号括起来的字符串。 我有一份从维基百科上刮下来的大文件,里面有很多这样的段落: "Theology translates into English from the Greek theologia (θεολογία) which derived from Τheos (Θεός), meaning "God," and -logia (-λογία),**[12]** meaning "utterances, sayings, or oracl

我正在努力找到一个正则表达式,它可以找到任何用方括号括起来的字符串。 我有一份从维基百科上刮下来的大文件,里面有很多这样的段落:

"Theology translates into English from the Greek theologia (θεολογία) which derived from Τheos (Θεός), meaning "God," and -logia (-λογία),**[12]** meaning "utterances, sayings, or oracles" (a word related to logos **[λόγος][Citation needed]**".
预期的结果将是:

"Theology translates into English from the Greek theologia (θεολογία) which derived from Τheos (Θεός), meaning "God," and -logia (-λογία), meaning "utterances, sayings, or oracles" (a word related to logos".
如有任何建议,将不胜感激。 谢谢

这些**也在文档中吗?你只提到方括号

如果是的话,正则表达式就是

(\*\*\[.*?\]\*\*)
如果它真的只是方括号,那么这与您所追求的匹配:

(\[.*?\])
您没有提到语言,但在Python中,这将由

import re

my_re = r'(\*\*\[.*?\]\*\*)'
my_string = '"Theology translates into English from the Greek theologia (θεολογία) which derived from Τheos (Θεός), meaning "God," and -logia (-λογία),**[12]** meaning "utterances, sayings, or oracles" (a word related to logos **[λόγος][Citation needed]**".'
my_corrected_string = re.sub(my_re, '', my_string)

print(my_corrected_string)

最好的建议是让你的问题更加精确,向我们展示你迄今为止所做的尝试,并阅读一些编程语言和正则表达式方面的知识。谢谢!这正是我需要的。抱歉,没有提供足够的信息。我在JS中使用了这个,它工作得非常好。