I’m creating a MTG card generator with JS, and I was wondering how I would go about replacing my Integers in the card cost using regex? (more for learning than publishing)
card_cost is just a input text value from a user, I want to be able to separate the integers with spaces IE: user enters: “10 1 2” Ints should get replaced but spaces should be kept.
would start like this:
if(card_cost)
{
card_cost=card_cost.replace(/INTEGER/g,"<span class='card_costnum' src='numsymbol.png' ></span>");
}
The attempt here is to replace the integers with themselves held inside a span to display a background image per number.
Now that I have had time to think about this I’m assuming I’ll need to get an array of the integers so I can pass them back through within a span, replacing wont be enough to catch more than one integer correctly I assume.
In javascript
replacefunction,$&refers to the search string itself, so you can writereturns
To replace each digit individually, just remove
+:returns