Linux 安装路径的正则表达式,用于验证用户在 java 脚本中输入的路径值

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

我的表单中有一个 Linux 安装路径的输入字段 我需要正则表达式来验证以下情况:

不应允许用户输入

/, /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

应该允许用户输入

/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

我正在尝试这个:^(.+)\/([^/\s]+)$

但它适用于如下负面情况:

/, /bin, /dev, /etc, /mnt, /opt, /run,/srv, /sys, /tmp, /usr, /var, /lib,  /proc, /sbin, /root, /boot, /home,  /lib64, /media, /opt/folde r, /opt/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

请这里的任何人都可以帮助我谢谢

试试这个正则表达式:^(\/[a-zA-Z0-9_-]+){2,}$(?<!^(\/usr\/bin)|(\/usr\/lib)|(\/usr\/lib64)|(\/usr\/sbin)$)

demo这里