Remove character if NOT between two letters
Problem Description:
Suppose that I have a text like below
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
I want to remove -
character if it is NOT between two characters ([a-zA-Z]). So, the desired output is:
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
How can I write a regex to match this case?
Solution – 1
Remove what is preceded by something that is not [a-zA-Z]
AND everything that is not followed by [a-zA-Z]
:
(?<![a-zA-Z])-|-(?![a-zA-Z])