Are you sure? I am a little surprised by this. I would think that if your regex is greedy enough you should be able to match it. Note removing the the dot from the boundary characters breaks linkifying words at the end of the sentence.
I did a little test with your regex below on regex101.com and it seems to work with the current boundary characters, see regex101: build, test, and debug regex
Note that if I understand your purpose correctly, you may need to turn some of your capturing groups into non-capturing groups with (?:)
The inability of using | is very annoying, agreed. Note that for ID|id part you can just use the i modifier to make the regex case insensitive. For the numbers if you really need the exact range between 1-10 and 1-100 then it’s tricky, relaxing to 1-19 and 1-199 would make it easier.
Here’s your regex with non-capturing groups that I think should work
I found two main issues with the built-in watched words
cannot add complex regexes: An error occurred: Word is too long (maximum is 100 characters)
cannot use arbitrary character as word boundary: namely underscore
also inability to edit rules or change order of execution is less then ideal
PR for the component exposes word boundaries to the user, and there are no issues with long regexes (apart from inability to use |, which is also addressed in PR).
Otherwise watched words work perfectly, and If these can be addressed in core I’m all for it.
This theme component you linked is an adaptation of Sam’s that I did as a workaround for a need you described in another topic.
They are simple theme components which only change how these words are rendered in a post (Sam’s converts specific words to links, mine converts specific words to images) based on the theme component settings, which are only managed by admins.
The feature you describe can’t be done in a theme component, it would need a plugin to store a per-user set of (word, image url) in the database and the word to image conversion should be done server-side, when building the cooked post (as HTML) content. These can’t be done in a theme component, which is only frontend/client-side code (if you hire someone to do this work it’s critical that they understand these details).
This is out of scope of this theme component and would need a way more involved work. The suggestion is to post the details of how you want this feature to behave on marketplace and you can hire someone here with prior experience with the Discourse internals to help you.
It’s been brought up many times in this topic, but I’d like to check again; is there any way to restrict this to a certain category or exclude categories? I would like to use this in our beginner’s category to have links to all the basic terms newbs need to learn, but in other areas, these would just be annoying to the experienced users. Thanks!
@Canapin you overlooked my issue: it’s not about repeated words, but about repeated pattern replacement of a single word: the URL contains the pattern to be replaced twice.
Since the /g pattern substitution option is default in the plugin, it should apply to all occurrences of $1 in the replacement, not just for the first one.
It’s a different case than having the keyword appear multiple times in a sentence, line, or paragraph. The replacement should account for multiple occurrences of the selection.
Good to know linkify only does one, but would love it one per post. I may have to try this out today, watched words is unbearable at times when it finds a match.