Check if the last char of the string fulfils the regular expression

I need to check if the last char of the string fulfils the regular expression. This if statement is not working. What’s wrong?
if (/[+-=*/]/.test(prevNum.slice(-1))) { ...code... }

Hello there,

It might help to see more code. However, this regex has one mistake:

/[+-=*/]/

The forward slash is not escaped

Hope this helps

just please write for me the if condition that will be true if the last char of the prevNum is the plus, minus, equals, asterisk or forward slash

try yourself, you can use a tool like this to test your code: https://regex101.com/

1 Like