Hashtag RegEx for SQL query

So, I'm trying to include hashtag search in posts in my application. I came up with some close regular expressions, but none of them work. Let's say I have a line:

#i keep #hashtags in my mom's attic. She says I am her number #1 son. Why I'm not num#ber #2: http://pics.com/pic#thepic

I would like RegEx to match:

  • I am

  • Hashtags

  • 1

  • 2

I want it to not specifically match the HTML objects, #anchors in the URLs, hashtags that start in the middle of the word, and any final punctuation after the hashtag. I also want to make sure that it matches the hashtag at the beginning of the line, as well as the hashtags that are fully numeric. I want him to make hyphens and underscores in hashtags. This is for a MySQL query, so Lookaheads and Lookbacks will not work.

Currently I'm stuck:

#([A-Za-z0-9_]+)

. RegEx - , . !

+3
2

, , , :

WHERE mycolumn REGEXP '^#[[:alnum:]]' OR mycolumn REGEXP ' #[[:alnum:]]'

, SQL , 1 () 0 ( ). hashtag, .

+2

, 3 :

`txt` REGEXP '^#[0-9a-zA-Z]+[: ,]';
OR `txt` REGEXP '[: ,]#[0-9a-zA-Z]+[: ,]';
OR `txt` REGEXP '[: ,]#[0-9a-zA-Z]+$';

, ,

CONCAT(" ",`txt`," ") REGEXP '[: ,]#[0-9a-zA-Z]+[: ,]';

, . , [: ,] , , '...

0

Source: https://habr.com/ru/post/1757402/


All Articles