0

I am not finding solution to add variable inside following RegEx

val.replace(/[^\d.]/gm,'')

Basically I need to change the . to variable.
Something like

val.replace("/[^\d"+sepaeator+"]"/gm,'')
Aleksey Solovey
  • 4,153
  • 3
  • 15
  • 34
vinod
  • 49
  • 1
  • 5
  • 4
    Use the constructor `new RegExp`. See [documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp). – trincot Jul 23 '18 at 14:20

1 Answers1

0

Use a RegExp instance (mdn):

const regex = new RegExp(`[^\d${separator}]`, 'gm');
val.replace(regex, '');
Fissure King
  • 1,250
  • 7
  • 17