英文:
Remove both the square brackets and their contents, as well as any occurrence of a comma or hyphen that follows the closed bracket in Notepad++
问题
我正在寻找在Notepad++中使用的正则表达式,用于删除所有方括号及其内容,以及在封闭括号后跟随的逗号或连字符的任何出现。正则表达式应该检测文本中需要删除的以下示例:
[1]–[5]
[Alibaba], [7], [8]
[1-2]–[5]
我不在乎逗号后面的空格,它们可以保留。
到目前为止,我可以通过\[[^\]]*\]
捕获括号及其内容。
英文:
I am looking for a regex to use in Notepad++ for deleting all square brackets and their contents, as well as any occurrence of a comma or hyphen that follows the closed bracket. The regex should detect the following examples inside the text for removal:
[1]–[5]
[Alibaba], [7], [8]
[1-2]–[5]
I don't care about the spaces after comma and they can stay.
So far I could catch the brackets and their content by \[[^\]]*\]
.
答案1
得分: 1
你可以这样扩展你的正则表达式来捕获后面的逗号和连字符:\[[^\]]*\](?:,|-)?
英文:
You can extend your regex this way to capture following comma and hyphen:\[[^\]]*\](?:,|-)?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论