Regex for Linux mount path to validate user enter path value in java script

岁酱吖の 提交于 2020-05-15 21:19:40

问题


I have a input field for Linux mount path in my form I need regex to validate following cases :

Should not allow user to enter

/, /bin, /dev, /etc, /mnt, /opt, /run,/srv, /sys, /tmp, /usr, /var, /lib,  /proc, /sbin, /root, /boot, /home,  /lib64, /media, /opt/folde r, /opt/folder/, /usr/bin, /usr/lib, /usr/lib64, /usr/sbin

Should allow user to enter

/opt/folder, /var/folder, /tmp/folder
/bin/foldername, /boot/foldername, /devfoldername, /etc/foldername, /home/foldername, /lib/foldername, /lib64/foldername, /media/foldername, /mnt/foldername, /opt/foldername, /proc/foldername, /root/foldername, /run/foldername, /sbin/foldername, /srv/foldername, /sys/foldername, /tmp/foldername, /usr/foldername, /var/foldername

i'm tring with this one: ^(.+)\/([^/\s]+)$

but it is working for negative case like below:

/, /bin, /dev, /etc, /mnt, /opt, /run,/srv, /sys, /tmp, /usr, /var, /lib,  /proc, /sbin, /root, /boot, /home,  /lib64, /media, /opt/folde r, /opt/folder/

positive case like below:

/bin/foldername, /boot/foldername, /devfoldername, /etc/foldername, /home/foldername, /lib/foldername, /lib64/foldername, /media/foldername, /mnt/foldername, /opt/foldername, /proc/foldername, /root/foldername, /run/foldername, /sbin/foldername, /srv/foldername, /sys/foldername, /tmp/foldername, /usr/foldername, /var/foldername

please can anyone here help me out thanks


回答1:


Try with this regex: ^(\/[a-zA-Z0-9_-]+){2,}$(?<!^(\/usr\/bin)|(\/usr\/lib)|(\/usr\/lib64)|(\/usr\/sbin)$)

Look demo here



来源:https://stackoverflow.com/questions/61494926/regex-for-linux-mount-path-to-validate-user-enter-path-value-in-java-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!