【发布时间】:2015-11-07 17:03:29
【问题描述】:
许多 Instagram 帖子以过多的主题标签结尾,例如:
"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"
我希望处理字幕以在最后删除主题标签集合,同时保持其余部分完好无损。这样做的好方法是什么?我确信我可以找到一种蛮力的方式,但我希望能对一个优雅的解决方案有所了解。不一定是实际代码。 :)
根据 Burna 的评论进行编辑:预期结果是:
"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"
根据 Alan Moore 的回答进行编辑:这非常有效,但并非在所有情况下都适用。例如,如果输入文本是:
"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"
...它会从“#张家界”开始被切断。
我认为可能需要更多的逻辑,也许将字符串拆分为数组;检查它是否以主题标签结尾;如果有,那么有多少;如果超过 X (4?),则从最后一个完整系列中的第一个中删除。
【问题讨论】:
-
处理后能不能加上预期的结果?
-
欢迎来到 SO!您的问题被自动格式化破坏了;您可以查看编辑历史以查看我做了什么来修复它(当您使用它时,请查看help page 以查看还有什么可用的)。您应该始终在此处预览您的帖子并进行校对。 ;)
-
@burna 我已经编辑了这个问题,但我认为 Alan Moore 已经回答了它:)
-
@WalterVos 太好了,然后通过接受答案来感谢他的努力:)
-
@burna 在进一步查看 Alan 的答案后,我发现它还没有完全到位。
标签: php regex instagram text-processing