'matching a folder path with regex with forward slash

I have a following regex to match a folder name. What I am trying to get is to match a string with letter, digits, dot, hyphen, underscore and forward slash such that the string doesn't need to start or end with forward stash or dot:

/^([a-zA-Z0-9_][a-zA-Z0-9.\/_\-])[.a-zA-Z0-9_-]{1,253}[^(.|/|\\)]$/

I need to match folder name foo.com/sdsds.

But the regular expression is not matching /.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source