Dart Feld
Dart Feld

Reputation: 41

ignoring certain characters with regex

I'm reading a text file where I'm adding words to a data structure and I have the following line.

I'm trying to use regex to delete the apostrophe from the tis but I want to keep it where it says Quran. I basically want the regex expression to ignore the apostrophe if it is between characters.

I have something like but I'm pretty new to Regex. Any ideas on what I should do or what parts of regex I should look at.

('\w)|(\w+'\w+)

it highlights the words only with apostrophes but I can't seem to figure out how to "negate" the second expression.

Upvotes: 0

Views: 49

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520948

Here is a regex which will target apostrophe only if it does not fall in between two characters:

(?<=\s|^)'(?=\w)|(?<=\w)'(?=\s|$)

Demo

Upvotes: 1

Related Questions