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:

  1. first of all, let's use anchors define begin&end of string: ^$
  2. i want: no "space", we've got \s matches non-white space character: ^\s+$
  3. no "../", let's add negative lookahead ^(?!.*[.][.]/)\s+$, note don't need escape dot inside character class. forwardslash, we'll use different delimiters
  4. one optional "/", add negative lookahead prevents 2 forwardslashes ^(?!(?:.*/){2})(?!.*[.][.]/)\s+$
  5. let's define delimiters , add s modifier match newlines .: ~^(?!(?:.*/){2})(?!.*[.][.]/)\s+$~s , here go online demo

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -