I'm trying to use this formula to extract hashtags from a cell. I got it from this very old topic.
=trim(regexreplace(A2, "((^|\s)[^#]\S*)|([^#\w\s]\S*)", ""))
Example source:
"This is a line before a line break.
#missinghashtag #2ndhashtag #3rdhashtag"
Current outcome:
#2ndhashtag #3rdhashtag
Desired outcome:
#missinghashtag #2ndhashtag #3rdhashtag
It mostly works, but I have found a small issue that I'm unable to debug as I'm clueless about REGEX.
It's skipping the first hashtag of a new paragraph. I guess it tries to find words that start with #, but a "break" counts as an invisible character before the #, so what happens is that the first hashtag doesn't get extracted. If I add a space after the break and before the first #, it suddenly works. And also I there's no space before the break, it also works. But would like to fix it to be bulletproof.
I only need to fix that. It would be highly appreciated.
Edit: Actually, I tested some more and if I add a hashtag before the break then something strange happens. The earlier conflictive hashtag works, and the one before the break works too, but they are returned with the break in between, which ideally I'd also like to remove.
Example source:
"This is a line before a line break. #thishashtagworks
#missinghashtag #2ndhashtag #3rdhashtag"
Current outcome:
"#thishashtagworks
#missinghashtag #2ndhashtag #3rdhashtag"
Desired outcome:
#thishashtagworks #missinghashtag #2ndhashtag #3rdhashtag
#missinghashtag #2ndhashtag #3rdhashtag
i.stack.imgur.com/v5fLo.png I copy / pasted the sample text and the formula, just changing A2 to A1 to save space. Maybe the original source is some sort of hidden characters (html entities, unicode, ...?). Please add more details about what is the source of the sample text, i.e. if you typed directly into the edit box or if you copied and pasted, if you copied and pasted, please use the web browser inspector tool to check the source code of the original text.