Regex to conditionally replace Twitter hashtags with hyperlinks

前端 未结 4 828
野的像风
野的像风 2020-12-05 16:49

I\'m writing a small PHP script to grab the latest half dozen Twitter status updates from a user feed and format them for display on a webpage. As part of this I need a rege

4条回答
  •  被撕碎了的回忆
    2020-12-05 17:01

    I found Gazlers answer to work, although the regex added a blank space at the beginning of the hashtag, so I removed the first part:

    (^|\s)
    

    This works perfectly for me now:

    #(\w*[a-zA-Z_0-9]+\w*)
    

    Example here: http://rubular.com/r/dS2QYZP45n

提交回复
热议问题