I am having a hard time correctly matching a variable ($myvar) using MySQL REGEX.
My first thought was to match the word (\b), but this will match both "testtype" and "edit-testtype" in my example below, which I don't want:
SELECT "edit-testtype, themes, upload, plugin-editor" REGEXP '\\b$myvar\\b';
SELECT "edit-testtype, themes, upload, plugin-editor" REGEXP '\^(?!-)\\b$myvar\\b';
If you want to try a regex way, you may use
REGEXP CONCAT('(^|[^-])[[:<:]]', $myvar', '[[:>:]]')
This won't work if your
$myvar contains special chars like
+ - they would need to be escaped.
(^|[^-]) matches the start of string or a non-hyphen,
[[:<:]] matches a leading word boundary and
[[:>:]] matches the trailing word boundary.
If the search term cannot be followed with a hyphen, turn