Skip to content

Instantly share code, notes, and snippets.

@benfrain benfrain/wrap.ts
Last active Sep 10, 2018

What would you like to do?
Finds numbers and currency codes and wraps them in an element
* @param inputString a string of text that may or may not include numbers and a currency unit
* @returns a string of text where a number followed by a currency unit is wrapped in spans for styling
function wrapUnits(inputString: string) {
let regNum = new RegExp("([0-9]+)", "gm");
let regUnit = new RegExp("(GBP|EUR)", "gm");
// It needs to match the currency unit or we are not interested
if (inputString.match(regUnit)) {
let newString = inputString.replace(
`<span class="cur-MoneyGroup">$1`
newString = newString.replace(
`<span class="cur-MoneySub">$1</span></span>`
return newString;
} else {
return inputString;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.