An user was kind enough to help me out with my regex in PHP, but now I'm realizing that I need it in JS too. I've been spending a crazy amount of time testing/experimenting, but without success.
In JS, I would like to turn this :
[data-user="12345-6789" data-userId="3456-789"]John Smith[/] ...Blablabla some other text... [data-user="4567-891011" data-userId="5678-9101112"]Foo Bar[/]
Into this :
<span data-user="12345-6789" data-userId="3456-789">John Smith</span> ...Blablabla some other text... <span data-user="4567-891011" data-userId="5678-9101112">Foo Bar</span>
Here is my PHP regex, which works perfectly :
$regex = '~\[(data-user="[\d-]+")\s+(data-userId="[\d-]+")\]\s*(.+?)\s*\[\/\]\s*(.*)~is';
while (preg_match($regex, $string)) {
$string = preg_replace($regex, "<span $1 $2>$3</span>$4", trim(strip_tags($string)));
}
P.S. I'm fully aware that parsing HTML with a regex is frowned upon, but since everything is consistent, I thought this would be the best approach.
Thank you very much.