regex - Regular expression for path validation? -
i have path , need write regular expression filter path common-io library.
the path should not contain:
req/com/res
,res/com/req
,req/al/res
,res/al/req
,_svn
and path should end .xml
.
fileutils.listfiles(afile, new regexfilefilter("^(.*?)"), truefilefilter.instance)
if this, returns xmls.
i don't have idea regex; please give idea how this?
you can use following regex:
^(?i)(?!.*(?:re[qs]/(?:com|al)/re[sq]|_svn)).*\\.xml$
see demo
the (?i)
pattern makes case-insensitive. remove if want make search case-sensitive. (?!.*(?:re[qs]/(?:com|al)/re[sq]|_svn))
pattern makes sure not allow of forbidden strings inside path.
if want account whole words, add \b
:
^(?i)(?!.*\\b(?:re[qs]/(?:com|al)/re[sq]|_svn)\\b).*\\.xml$
see another demo
note in java-style regex not need escape /
, have double-escape special characters.
Comments
Post a Comment