Given the test string:
<div class="comment-quoter">Comment by <strong>Tom</strong>
I want to change it to
[quote=Tom]
I’ve got as far as this but it gets no matches:
PostTxt = PostTxt.replace(new RegExp("<div class=\"comment-quoter\">Comment by <strong>{(.+),}</strong>", "g"), '[quote=$1]')
Try:
The round brackets denote the
$1capture group, so the curly brackets and comma would match literals and aren’t necessary.Dependent on what you’re expecting, you can make it less greedy by being more specific about the characters you’re matching for the capture group:
(\w+)would match one or more alpha-numeric characters and would return correct matches if you have more than one quote in your input string.