对正则表达式的路径和字母数字字符 [英] Regex for path and alpha numeric character
本文介绍了对正则表达式的路径和字母数字字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要正则表达式来验证路径如
I need regex to validate path like
/addd/dddd
aaaa/bbbb/
a1233/dddd
but not
@ddd/aaaa
或任何其他标志,我应该怎么做呢?
or any other symbol,how should I do that?
推荐答案
这一个尝试(考虑仅 AAA
不能是一个路径,如果是这样,用管道将其添加):
Try with this one(considering only aaa
can not be a path, if so, add it with pipe):
^((?:/[a-zA-Z0-9]+)+/?|/?(?:[a-zA-Z0-9]+/)+)[a-zA-Z0-9]*$
(?:/ [A-ZA-Z0 -9] +)+ /
是匹配像 AA / AA /
和路径/(?:?[一-za-Z0-9] + /)+
是匹配像 / AA / AA目录
。和 [A-ZA-Z0-9] *
为其他名称检查时,该目录的格式是 AA / AA
(?:/[a-zA-Z0-9]+)+/?
is matching paths like aa/aa/
and /?(?:[a-zA-Z0-9]+/)+
is matching directories like /aa/aa
. And [a-zA-Z0-9]*
is checking for additional names when the directory format is aa/aa
.
这篇关于对正则表达式的路径和字母数字字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文