php - How to multiple regexes into one regex -
hi have 3 regex preg_match in 1 if..
i want know if it's possible mix 3 regex in 1?
this if 3 regex :
if(!preg_match("#\s#",$file) && !preg_match("#\.\.\/#",$file) && (preg_match_all("#/#",$file,$match)==1)): (i want: no "space" , no "../" , 1 "/")
thanks help.
edit
add needed in list point (more readable):
- no "space"
- no "../"
- 1 "/"
it's quite simple. let's start step step crafting regex:
- first of all, let's use anchors define begin&end of string:
^$ i want: no "space", we've got\smatches non-white space character:^\s+$no "../", let's add negative lookahead^(?!.*[.][.]/)\s+$, note don't need escape dot inside character class. forwardslash, we'll use different delimitersone optional "/", add negative lookahead prevents 2 forwardslashes^(?!(?:.*/){2})(?!.*[.][.]/)\s+$- let's define delimiters , add
smodifier match newlines.:~^(?!(?:.*/){2})(?!.*[.][.]/)\s+$~s, here go online demo
Comments
Post a Comment