Edit:
Annoyed that this was marked as a duplicate when the solution is very clearly different...
To give some more information on why I am asking this, I am building a web game. In the game, there are items that you can build which costs certain ingredients.
What the function does is that it loops through all the requirements of the item and builds out a string that looks something like this:
let costStr = `
<span class='enough'>coal: 5, </span>
<span class='not-enough'>iron: 5, </span>
<span class='enough'>copper: 10, </span>
`
And then I append the string into an element on the page: costStr.innerHTML = costStr
The problem with this was because unlike other stackoverflow questions about removing commas, I didnt want to remove everything after the last comma because that would remove the span
tag as well.
Example input string: <span>test, </span><span>test, </span><span>test, </span>
What I want: <span>test, </span><span>test, </span><span>test </span>
Tried some solutions that I found online but those don't take into account html tags that might be at the end of the string.
Is this possible with regex? Just replacing the last comma within a string with nothing?
Thanks!