Here is the code snippet I am currently using:
var user_pattern = this.settings.tag;
user_pattern = user_pattern.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); // escape regex
var pattern = new RegExp(user_pattern.replace(/%USERNAME%/i, "(\\S+)"), "ig");
The value stored in this.settings.tag
is a string like "[user=%USERNAME%]" or "@%USERNAME%". This code utilizes pattern.exec(str)
to identify any username within the respective tag and it functions correctly. For instance, if str = "Hello, [user=test]"
, then pattern.exec(str)
will detect test
.
Although it works properly, I want to prevent matches from occurring if the string is enclosed in [nocode][/nocode]
tags. To illustrate, if
str = "[nocode]Hello, [user=test], how are you?[/nocode]"
, the pattern.exec(str)
should not yield any results.
I'm uncertain about where to initiate changes. I attempted inserting (?![nocode])
before and after the pattern without success. Any assistance would be highly appreciated.