Search code examples
regextextwrangler

Regex, how to select everything except pattern?


I'm working on TextWrangler, I want to delete every word from a text that doesn't have an hashtag before. Example:

Looking for a simple #homemade gift for the #holidays? 
This #DairyFree #DarkChocolate #Fudge recipe is simple and absolutely delicious: http://sddf.us/fudge

I would like to have only

#homemade #holidays #DairyFree #DarkChocolate #Fudge

also I would like to use TextWrangler, because I know nothing about Java and PHP. I used this regular expression #\w+ which select the hashtag words, but I don't understand how to delete everything else. Thank you


Solution

  • You can replace all (^|\s|[^#\w])+[^#\s]+ by empty strings.

    Demo