I'm playing around with regex, and I want to check valid folder path. This is the code.
return $folder->path('../../folder');
How to check if ../../
is valid? It can be ./../
or .././
or ...//./`. Can it be done with regex or something else?
Too long for a comment, so I'm posting this here
The title of the answer is confusing. You tell about checking some valid directory. But reading the comments a more appropiate title would have been something like "Validate custom rules against a path-like string".
Where your rules seem to be (according to the comments)
../
.
or ..
wihin the rest of the directory (excluding prefix)text
or /text
If so, this may work for you: ^(\.\.\/(?:\.\.\/)*)?(?!.*?\/\/)(?!(?:.*\/)?\.+(?:\/|$)).+$