Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove character if NOT between two letters

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading