PHP Level 2, Regular Expressions

6 Questions | Total Attempts: 916

Settings
Please wait...
PHP Quizzes & Trivia

This quiz is a test of basic PCRE, aka, preg_match(). Difficult concepts in regexes are not covered. Passing the test indicates that you have a basic understanding of regexes.


Questions and Answers
  • 1. 
    In the following statement, what does the "+" symbol mean?preg_match('/^[0-9]+$/', $data)
    • A. 

      Any character

    • B. 

      One character between 0 and 9

    • C. 

      One or more characters between 0 and 9

    • D. 

      Zero or more characters between 0 and 9

    • E. 

      Any character between 0 and 9 followed by a $

  • 2. 
    • A. 

      98090

    • B. 

      213-99

    • C. 

      415

    • D. 

      1-2345

    • E. 

      5-99

  • 3. 
    Rank these three function in the order of their typical speed, slowest to fastest: preg_match(), strpos(), ereg().
    • A. 

      Preg_match, strpos, ereg

    • B. 

      Ereg, preg_match, strpos

    • C. 

      Ereg, strpos, preg_match

    • D. 

      Preg_match, ereg, strpos

  • 4. 
    How long is the shortest string that would match this regex:preg_match('/^[a-z]+[0-9]*[A-Z]{2,10}$/')
    • A. 

      0 characters (empty string)

    • B. 

      1 character

    • C. 

      2 characters

    • D. 

      3 characters

    • E. 

      4 characters

  • 5. 
    What is the value of $matches[1]?preg_match('/([0-9]{3})-([0-9]{3})-([0-9]{4})/', "TEL 323-555-1212", $matches);
    • A. 

      TEL

    • B. 

      323

    • C. 

      555

    • D. 

      1212

  • 6. 
    Which of the following is NOT a typical use for regular expressions in PHP.
    • A. 

      Validating input data

    • B. 

      Dividing input text into substrings.

    • C. 

      Converting hexadecimal into decimal.

    • D. 

      Replacing strings with other strings.