regex 如果不在两个字母之间,则删除字符[duplicate]

ryevplcw  于 2022-12-14  发布在  其他
关注(0)|答案(1)|浏览(111)

此问题在此处已有答案

Regex to match character if not between digits(2个答案)
7天前关闭。
假设我有一个文本如下

Lorem Ipsum-is simply dummy- text of the printing and -typesetting industry. 
Lorem Ipsum - has been the industry's standard dummy text ever since the 1500s
a-z

如果-字符不在两个字符([a-zA-Z])之间,我想删除它。因此,所需的输出为:

Lorem Ipsum-is simply dummy text of the printing and typesetting industry. 
Lorem Ipsum  has been the industry's standard dummy text ever since the 1500s
a-z

如何编写正则表达式来匹配这种情况?

fbcarpbf

fbcarpbf1#

删除前面不是[a-zA-Z]的内容以及后面不是[a-zA-Z]的所有内容:

(?<![a-zA-Z])-|-(?![a-zA-Z])

相关问题