Regex Pattern for both @, #, and h/

Afternoon,

I’m trying to use bbcode to implement clickable hashtags and stuff, but I suck at implementation.

This is the regex pattern. As you can see, @ works, but is by itself, I’d like to allow for the # symbol along with a custom h/ symbol if possible. h/ would work similar to reddit insofar as r/askreddit becomes a hyper-link.

(^|\s)(@|#|h\/)(\w{3})

Thank you so much for replying

I tried this code but it’s doing a few weird things.

A. It cuts off the first 3 letters of the text

B. It doesn’t highlight the rest of the word in blue

image

@dorilama

Chatgpt

there are 3 groups in the expression, you need to modify your replacement accordingly (you want $3 somewhere). The quantity modifier at the end is for exactly 3 characters, you can add a coma after the 3 to make it from 3 chars to the end of the word