JavaScript Regex for Path without leading or trailing slashes
I’m struggling to figure out a Regex pattern for JavaScript that will trim a path of it’s preceding and trailing slashes (or hashes/extensions)
For example:
path/
/path
/folder/path/
/folder/folder/path
/folder/path#hash
/folder/path.ext
Should return:
path
path
folder/path
folder/folder/path
folder/path
folder/path
I felt like I was getting close with the following, but it only selects text without any slashes, hashes, or periods.
^([^\/#.]*)(?![#.\/].*$)/gm
I’m trying to use this for Regex in a vuetify text-field validation, if that’s at all helpful.
Read more here: Source link