string-math icon indicating copy to clipboard operation
string-math copied to clipboard

recommendation on removing unused characters

Open mesqueeb opened this issue 4 months ago • 0 comments

we use this with text field user input.

if the user ends its string in any of these ways:

  • 100 + 100 +
  • 100.1 + 100.
  • 100 + 100 =
  • 1,000 + 1,000

we want it to still work, so we have to manually remove (1) any non math characters like (, separators) and any trailing math characters at the end like ., +, = etc.

Currently we wrote a regex that cleans up the user input before piping it through the string-math like so:

calculatorInput
      .replaceAll(/[^.0-9\-+*/^e()]/g, '')
      .replace(/[^0-9()]$/, '')

is there any advice you can give if this is a good way to do it?

mesqueeb avatar Sep 06 '25 18:09 mesqueeb