I believe the reason it won't match single characters, is that you have two instances of [^/]
in your regex. This means that it needs at least two characters that are not slashes for it to properly match. A quick solution to this is to use a regex OR operator to handle this case. Here's a modified version of your regex that matches all of your examples:
((^[^/].*[^/]$)|^[^/]$)
This can be broken into two segments
(^[^/].*[^/]$)
this first part is a shortened version of yours and will capture any strings with a length of 2 or more that don't start or end with a slash.
The second part on the other side of the OR operator (|
) is this
^[^/]$
This will match a single character lines that are not a slash.