Many Instagram posts end with a plethora of hashtags, for example:
"This is one of the amazing Mountains you can find in the National Forest Park in #Zhangjiajie #Chinawhich is where James Cameron drew his inspiration for the flying mountains in #Avatar..
Credit: @phototravelnomads
#pictoura #gydr
#destinationearth #earthpix #ourlonelyplanet#wonderful_earthLife #timeoutsociety#fantastic_earthpics #liveoutdoors #igglobalclub#awesomeearth #mist_vision #earthdeluxe
# #worldbestgram #mthrworld #fantastic_earth#famouscaptures #destination_wow #dreamlifepix#wonderful_places #igworldclub #ig_global_life
#natureaddict #beautifuldestinations #traveler #guider#locals"
I'm looking to process the captions to remove the hashtag collection at the end, while leaving the rest intact. What would be a good approach to doing this? I'm sure I can figure out a brute force way, but I'm hoping to get some thoughts on an elegant solution. Doesn't have to be actual code. :)
Edit per burna's comment: The expected result would be:
"This is one of the amazing Mountains you can find in the National Forest Park in #Zhangjiajie #Chinawhich is where James Cameron drew his inspiration for the flying mountains in #Avatar..
Credit: @phototravelnomads"
Edit per Alan Moore's answer: This works quite well, but not in every situation. For instance, if the input text would be:
"This is one of the amazing Mountains you can find in the National Forest Park in #Zhangjiajie #Chinawhich is where James Cameron drew his inspiration for the flying mountains in #Avatar"
... it would be cut off from "#Zhangjiajie" on.
I'm thinking there's probably a bit more logic required, perhaps splitting the string into an array; checking if it ends in hashtags; if so then how many; if more than X (4?), cut it off from the first one in the last complete series.