Regular Expressions - Study Mode
[#16] POSIX stands for
Correct Answer
(A) Portable Operating System Interface for Unix
[#17] Which of the following would be a potential match for the Perl-based regular expression /fo{2,4}/ ? 1. fol 2. fool 3. fooool 4. fooooool
Correct Answer
(B) 2 and 3
Explanation
Solution: This matches f followed by two to four occurrences of o.
[#18] Which among the following is/are not a metacharacter? 1. /a 2. /A 3. /b 4. /B
Correct Answer
(A) Only 1
Explanation
Solution: /A, /b and /B are metacharacters. A: Matches only at the beginning of the string. b: Matches a word boundary. B: Matches anything but a word boundary.
[#19] What will be the output of the following PHP code? <?php $username = "jasoN"
if ( ereg ( "([^a-z])" ,$username)) echo "Username must be all lowercase!"
else echo "Username is all lowercase!"
?>
Correct Answer
(B) Username must be all lowercase!
Explanation
Solution: Because the provided username is not all lowercase, ereg() will not return FALSE (instead returning the length of the matched string, which PHP will treat as TRUE), causing the message to output.
[#20] What will be the output of the following PHP code? <?php $text = "this istsome text thatnwe might like to parse."
print_r ( split ( "[nt]" ,$text))
?>
Correct Answer
(D) [0] => this is [1] => some text that [2] => we might like to parse.
Explanation
Solution: The split() function divides a string into various elements, with the boundaries of each element based on the occurrence of a defined pattern within the string.