I was working on a regex to check if all the symbols in the string are from the range of allowed ones.
My initial regex, which was working was:
| C | | copy code | | ? |
| 1 |
^[a-zA-Z0-9_-]*$ |
Later I decided to allow spaces and dots and wrote a new regex:
| C | | copy code | | ? |
| 1 |
^[a-zA-Z0-9_-\. ]*$ |
This one was not working! I’ve spent quite a time until I figured out that the peace “_-\.” was treated the same way as “a-z”. It assumed I am providing a scope. My issue was fixed after I escaped “-” and my final regex looked like this:
| C | | copy code | | ? |
| 1 |
^[a-zA-Z0-9_\-\. ]*$ |
