Q:

Delete any non-word character but spaces and a single quote inside the word

Want cleanup some texts. So, want remove anything but \w and \s, but also want keep the single ' inside the word. (e.g. want keep it in words like don't.
I could do
perl -plE "s/[^\w\s']//g" <<< "'a:b/c d????ef' don't"

which keeps the ' but it keeps it also at the begining or end of string, e.g. it prints
'abc def' don't

I'm unable to implement the keep this (?<\w)'(?=\w), e.g. remove the ' unless it is between two word characters.
The wanted result:
abc def don't

How to do this?

A:

You could do this:
s/[^\w\s']|(?<!\w)'|'(?!\w)//g

Delete everything that is either

a character that is not (a word character or a space or '), or
a ' that is not preceded by a word character, or
a ' that is not followed by a word character

The first clause will match (and remove) all characters that we obviously don't want to keep.
The second and third clause will remove all ' characters unless they're surrounded by word characters on both sides.

