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++

huangapple go评论51阅读模式
英文:

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:\[[^\]]*\](?:,|-)?

huangapple
  • 本文由 发表于 2023年6月11日 23:25:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76451169.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定