How to match a pound (#) symbol in a regex in php (for hashtags)

后端 未结 5 1197
孤独总比滥情好
孤独总比滥情好 2021-01-17 17:02

Very simple, I need to match the # symbol using a regex. I\'m working on a hashtag detector.

I\'ve tried searching in google and in stack overflow. One

5条回答
  •  既然无缘
    2021-01-17 17:22

    # does not have any special meaning in a regex, unless you use it as the delimiter. So just put it straight in and it should work.

    Note that \b detects a word boundary, and in #abc, the word boundary is after the # and before the abc. Therefore, you need to use the \b is superfluous and you just need #\w\w+.

提交回复
热议问题