Regex for relative file paths
Regular expressions can come in handy when you need to find strings. This Regual expression simply matches relative paths. It’s not perfect, but it gets the job done :)
(([^\./\\:*?<>|"]*)(/[^\./\\:*?<>|"]*)*/([^\./\\:*?<>|"]*\.[^\./\\:*?<>|"]+))
I should mention, that this regex is meant for python and also the relative path has to have a file ending. This means that, for example the path ‘path/without/filending’ doesn’t get matched by the regex, but ‘path/with/file.ending’ does.
Update:
^(\/?[^\/]+)(\/[^\/]+)*\/([^\/]*\.[^\/]+)$
This is the optimized version :) - a lot shorter. Check this site for trying regular expressions.