Search code examples
grepsublimetext3

How to delete all words that contain apostrophes in Sublime Text 3


I have a word list of over 10,000 words, but this is just a sample:

'Tis midnight
sev'n words spoke
th'Immortal night
A wonder-working pow'r
Wondrous deliv'rer to me

I want to delete all words that contain apostrophes so the list should look like this:

midnight
words spoke
night
A wonder-working
Wondrous to me

How can I do this using Sublime Text so it finds apostrophes and smart apostrophes ()?


Solution

  • You could use a character class['’] to match both variations of the apostrophes and match zero or more times a non-whitespace character \S* before or after the matched apostrophe followed by optional horizontal white-space chars.

    \S*['’]\S*\h*
    

    Regex demo


    A slightly more optimized version without preventing the first \S* causing backtracking could be using a negated character class [^\s'’]* to match until the first apostrophe.

    [^\s'’]*['’]\S*\h*
    

    Regex demo