Can someone help me with creating a regular expression in Typescript that can match the decimal separator character followed by a sequence of zeros in a string? I have tried to come up with an expression as shown below:
/\.0+\b/g
However, since the decimal separator is determined at run-time based on locale, I am constructing my expression in code using a variable called decimalSeperator
:
"/\\" + decimalSeperator + "0+\b/";
My plan was to escape the double backslash characters to a single backslash character before running the expression. But when I compile the JavaScript code, the double backslashes are not being escaped:
"/\\" + decimalSeperator + "0+\b/"
If I try using a single backslash instead, the code does not compile due to issues with escaping characters:
"/\" + decimalSeperator + "0+\b/";
- Error TS1005: ',' expected.
- Error TS1127: Invalid character.
- Error TS1002: Unterminated string literal.
I am unsure if this is a bug with Typescript or if I am approaching this problem incorrectly. Any insights would be appreciated.
Thank you.