Zend PHP 5.3 Certification Exam
Strings and Patterns
Functions and Arrays
Object Oriented Programming
Data Format & Types
Databases and SQL
Web Features 1
You want to search for such users who have not used any digit in their user names to register to your Website. Which of the following regular expressions will you use to accomplish the task?
Answer option B is correct.
The usage position of metacharacters in a regular expression determines the result of the regular expression. If caret (^) metacharacter is used inside a character list, it means the negation of a character list. Therefore, [^[:digit:]] looks for a pattern consisting of any non-digit character. Therefore, in the given scenario, you will use the [^[:digit:]] regular expression to accomplish the task.
Some of the predefined POSIX (Portable Operating System Interface) character classes are as follows:
[:alpha:] Alphabetic characters
[:lower:] Lower case alphabetic characters
[:upper:] Upper case alphabetic characters
[:digit:] Numeric digits
[:alnum:] Alphanumeric characters
[:space:] Non-printing space characters
[:punct:] Punctuation characters
[:print:] Printable characters
Answer options A and D are incorrect. The caret (^) metacharacter cannot be used at the end of any regular expression.
Answer option C is incorrect. The ^[[:digit:]] regular expression looks for matches that start with a digit.
Reference: PHP 5 Manual, Contents: "PCRE"
© 2013 Zend PHP Certification Exam