PHP Regular Expressions MCQs
PHP Regular Expressions MCQs : This section focuses on "Regular Expressions" in PHP. These Multiple Choice Questions (mcq) should be practiced to improve the PHP skills required for various interviews (campus interview, walk-in interview, company interview), placements, entrance exams and other competitive examinations.
1. Regular expressions are nothing more than a sequence or pattern of characters itself.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: True, Regular expressions are nothing more than a sequence or pattern of characters itself. They provide the foundation for pattern-matching functionality.
2. PHP offers functions specific to ________ sets of regular expression functions
A. 1
B. 2
C. 3
D. 4
View Answer
Ans : B
Explanation: PHP offers functions specific to two sets of regular expression functions, each corresponding to a certain type of regular expression. You can use any of them based on your comfort: POSIX Regular Expressions and PERL Style Regular Expressions
3. ______________ have a special meaning when used in the context of regular expressions.
A. ()
B. {}
C. []
D. $
View Answer
Ans : C
Explanation: Brackets ([]) have a special meaning when used in the context of regular expressions. They are used to find a range of characters.
4. Which of the following expression matches any character from uppercase A through uppercase Z?
A. [a-z]
B. [A-Z]
C. [a-Z]
D. None of the above
View Answer
Ans : B
Explanation: [A-Z] : It matches any character from uppercase A through uppercase Z.
5. Which of the following expression matches any string containing at least one p?
A. p*
B. p-
C. p^
D. p+
View Answer
Ans : D
Explanation: p+ : It matches any string containing at least one p.
6. What is use of expression p$?
A. It matches any string containing zero or more p's.
B. It matches any string containing zero or one p's.
C. It matches any string with p at the end of it.
D. It matches any string with p at the beginning of it.
View Answer
Ans : C
Explanation: p$ : It matches any string with p at the end of it.
7. The __________ function searches a string specified by string for a string specified by pattern, returning true if the pattern is found, and false otherwise.
A. ereg_replace()
B. ereg()
C. eregi()
D. eregi_replace()
View Answer
Ans : B
Explanation: The ereg() function searches a string specified by string for a string specified by pattern, returning true if the pattern is found, and false otherwise.
8. [:alpha:] can also be specified as ________
A. [A-Za-z0-9]
B. [A-za-z]
C. [A-z]
D. [a-z]
View Answer
Ans : B
Explanation: [:alpha:] is nothing but Lowercase and uppercase alphabetical characters.
9. How many functions does PHP offer for searching and modifying strings using Perl-compatible regular expressions.
A. 5
B. 6
C. 7
D. 8
View Answer
Ans : D
Explanation: The functions are preg_filter(), preg_grep(), preg_match(), preg_match_all(), preg_quote(), preg_replace(), preg_replace_callback(), and preg_split().
10. The spliti() function operates exactly in the same manner as its sibling split(), except that it is not case sensitive.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: True, The spliti() function operates exactly in the same manner as its sibling split(), except that it is not case sensitive.
Discussion