How to validate a Unix or Win path using RegEx [closed]

  java, path, regex, unix, windows

I am facing a problem with unix or windows paths which needs to be validated by regular expressions.
Preferably, using Patter and Matcher to check if paths are valid, otherwise retrun false.

Here’s some Unix path examples:

/folder/../folder/file.txt
/dev/null
file.txt
folder/logs/
~/user/some_logs

And Windows path examples:

file.txt
Program Filessome_file.exe
.to_do_list.txt
C:Users..Cygwin
.file

And these paths we need to avoid:

/folder1/folder2folder3
C:User/root
/dev/~/
C:/a/b/c/d
~folder
~/~
~~
C:FolderSubfolderC:

Thanks in advance)

Source: Windows Questions

LEAVE A COMMENT