Currently, I'm using this regular expression to detect Japanese hashtag and English hashtag.
\B([##][·・ー_0-90-9a-zA-Za-zA-Zぁ-んァ-ン一-龠]{1,24})(?=\W|$)
The rule is:
Hashtag must be started with # character.
Hashtag will be detected by space character and other special characters (!,@,&,*,%,$).
Example 1: Hello#guys. This is a #test. -> Valid hashtag: #test.
Example 2: Hello#guys. This is a #test!#message. -> Valid hashtag: #test and #message
Example 3: Hello#guys. This is a #test #message. -> Valid hashtag: #test and #message
Example 4: Hello#guys. This is a #test#message. -> Valid hashtag: #test
Example 5: #asdasdasdasdasdasdasdasdasd -> Valid hashtag: none
Example 6: # -> Valid hashtag: none
It works so far until I met these 2 specific cases with Japanese characters :(
#日本語#asd => Valid hashtag should be #日本語
#日本語日本語日本語日本語日本語日本語日本語日本語日本語 => Will not a valid hashtag
The regular expression above cant detect these 2 cases, I try a lot of ways but not find any solution so far.
Currently, I'm using this site for testing: https://regexr.com/
Please help, thanks in advance.
Thanks to @Ryszard Czech
The final solution will be, this will work exactly like Twitter hashtag:
/(?<![\p{L}0-9ー_])([##][一_0-90-9a-zA-Za-zA-Zァ-ン゙゚一-龠ぁ-ゔァ-ヴ]{1,24})(?![\p{L}0-9ー_])/gu