Skip to content
Advertisement

Bug while checking for symbols inside of a string?

I’m creating a small calculator script and I’ve got stumbled on a strange bug. Everything seems to work but not when I input anything starting with (. When I do that if gives false and the code inside of else executes. I’ve tried a lot of ways rewriting how should "$input" =~ [-,+,*,/,(,)] look like but nothing worked. Do you have any idea why that’s happening and how to solve this bug?

JavaScript

Advertisement

Answer

If you need to make sure your input consists of just certain characters, use this much simpler regex:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement