I am not a regular expression expert, and I rack my brains trying to make what seems very simple, and works in python 2.7: checks the URL path (without hostname) without a query string. In other words, a line starting with / allows alphanumeric values and does not allow any other special characters besides these: / . , -
I found this post , which is very similar to what I need, but it doesn’t work for me at all, I can test, for example, with aaa , and this will return true even if it does not start with / .
The current current regex that I have is as follows:
[^/+a-zA-Z0-9.-]
but it does not work with paths that do not start with / . For instance:
/aaa → true, this is normal/aaa/bbb true, this is normal/aaa?q=x → false, this is normalaaa true, this is NOT normal
source share