Skip to content

Instantly share code, notes, and snippets.

@Git-I985
Last active May 19, 2023 13:23
Show Gist options
  • Select an option

  • Save Git-I985/ceff2ba0685efbc9d815024782cd6f61 to your computer and use it in GitHub Desktop.

Select an option

Save Git-I985/ceff2ba0685efbc9d815024782cd6f61 to your computer and use it in GitHub Desktop.
Dollar Prices
/*
from: [
"$7 000",
"$7000",
"$70.002",
"7000 $",
"7% test, test to $7 000",
"7% test, test to $7000",
"7% test, test to 7000$",
"7% test, test to 7000 $",
"7000 $ test, 7000 $ test to $ 7 000"
]
to: [
"<span>$7 000</span>",
"<span>$7000</span>",
"<span>$70.002</span>",
"<span>7000 $</span>",
"7% test, test to <span>$7 000</span>",
"7% test, test to <span>$7000</span>",
"7% test, test to <span>7000$</span>",
"7% test, test to <span>7000 $</span>",
"<span>7000 $</span> test, 7000 $ up to <span>$ 7 000</span>"
]
*/
const wrapPrices = (str: string): string =>
str
.replaceAll(/(\d(\d| |\.)+\$)/gm, `<span>$&</span>`)
.replaceAll(/\$ ?(\d(\d| |\.)+)/gm, `<span>$&</span>`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment