Practice high-yield Programming & Software Development MCQs on Regular Expressions with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
29
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
35 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
29
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/29 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 29 questions answered.
Question 1 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
[:alpha:] can also be specified as.
Correct Answer: Option B — [A-za-z]
Detailed Academic Explanation:
[:alpha:] is nothing but Lowercase and uppercase alphabetical characters.
💡Key Conceptual Anchor:Regular Expressions
Question 2 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many functions does PHP offer for searching strings using POSIX style regular expression?
Correct Answer: Option A — 7
Detailed Academic Explanation:
ereg(), ereg_replace(), eregi(), eregi_replace(), split(), spliti(), and sql_regcase() are the functions offered.
💡Key Conceptual Anchor:Regular Expressions
Question 3 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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: Option B — Username must be all lowercase!
Detailed Academic Explanation:
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.
💡Key Conceptual Anchor:Regular Expressions
Question 4 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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: Option D — [0] => this is [1] => some text that [2] => we might like to parse.
Detailed Academic Explanation:
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.
💡Key Conceptual Anchor:Regular Expressions
Question 5 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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: Option B — 2 and 3
Detailed Academic Explanation:
This matches f followed by two to four occurrences of o.
💡Key Conceptual Anchor:Regular Expressions
Question 6 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which among the following is/are not a metacharacter? 1. /a 2. /A 3. /b 4. /B
Correct Answer: Option A — Only 1
Detailed Academic Explanation:
/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.
💡Key Conceptual Anchor:Regular Expressions
Question 7 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many functions does PHP offer for searching and modifying strings using Perl-compatible regular expressions.
Correct Answer: Option B — 8
Detailed Academic Explanation:
The functions are preg_filter(), preg_grep(), preg_match(), preg_match_all(), preg_quote(), preg_replace(), preg_replace_callback(), and preg_split().
💡Key Conceptual Anchor:Regular Expressions
Question 8 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $foods = array ( "pasta", "steak", "fish", "potatoes" ); $food = preg_grep ("/^s/", $foods); print_r ($food); ?>
Correct Answer: Option C — Array ( [1] => steak )
Detailed Academic Explanation:
This function is used to search an array for foods beginning with s.
💡Key Conceptual Anchor:Regular Expressions
Question 9 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Say we have two compare two strings which of the following function/functions can you use? 1. strcmp() 2. strcasecmp() 3. strspn() 4. strcspn()
Correct Answer: Option D — All of the mentioned
Detailed Academic Explanation:
All of the functions mentioned above can be used to compare strings in some or the other way.
💡Key Conceptual Anchor:Regular Expressions
Question 10 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following functions will convert a string to all uppercase?
Correct Answer: Option A — strtoupper()
Detailed Academic Explanation:
Its prototype follows string strtoupper(string str).
💡Key Conceptual Anchor:Regular Expressions
Question 11 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php echo str_pad ( "Salad", 5)." is good." ; ?>
Correct Answer: Option D — Salad is good
Detailed Academic Explanation:
The str_pad() function pads a string with a specified number of characters.
💡Key Conceptual Anchor:Regular Expressions
Question 12 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $author = "nachiketh@example.com" ; $author = str_replace ("a","@",$author); echo "Contact the author of this article at $author." ; ?>
Correct Answer: Option C — Contact the author of this article at n@chiketh@ex@mple.com
Detailed Academic Explanation:
The str_replace() function case sensitively replaces all instances of a string with another.
💡Key Conceptual Anchor:Regular Expressions
Question 13 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $url = "contact@examveda.com" ; echo ltrim(strstr ($url, "@"),"@" ); ?>
Correct Answer: Option D — examveda.com
Detailed Academic Explanation:
The strstr() function returns the remainder of a string beginning with the first occurrence of a predefined string.
💡Key Conceptual Anchor:Regular Expressions
Question 14 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $number = array ( 0 , 1 ,two,three,four, 5 ); $num = preg_grep ( "/[0-5]/" , $number); print_r ($num); ?>
Correct Answer: Option D — Array([0]=>0 [1]=>1 [5]=>5)
Detailed Academic Explanation:
The preg_grep function is used to search an array for specific patterns and then return a new array based on that filtering.
💡Key Conceptual Anchor:Regular Expressions
Question 15 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output if we replace the line $num = preg_grep(“/[0-5]/”, $number); with $num = preg_grep(“/[0-5]/”, $number, PREG_GREP_INVERT);?
Correct Answer: Option B — Array([2]=>two [3]=>three [4]=>four)
Detailed Academic Explanation:
When we include PREG_GREP_INVERT, this will invert our data, so instead of outputting numbers it will output our non-numeric values.
💡Key Conceptual Anchor:Regular Expressions
Question 16 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following functions is used to search a string?
Correct Answer: Option A — preg_match
Detailed Academic Explanation:
The function returns 1 if search was successful else returns 0.
💡Key Conceptual Anchor:Regular Expressions
Question 17 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $name = "What is your name?" if ( preg_match ( "/name/" ),$name) echo "My name is Will Pitt " ; else echo "My name is not Will Pitt " ; if ( preg_match ( "/are/" )) echo "I am great" else echo "I am not great" ; ?>
Correct Answer: Option C — My name is Will Pitt I am not great
Detailed Academic Explanation:
The code uses preg_match to check for a keyword and replies based on whether it is true (1) or false (0).
💡Key Conceptual Anchor:Regular Expressions
Question 18 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $str = "Hello! My name is Cameron Fox. Coffee?" $find = array ( '/is/','/coffee/' ); $replace = array ( '/was/','/tea/' ); echo preg_replace ($find, $replace, $str); ?>
Correct Answer: Option D — Hello! My name was Cameron Fox. Coffee?
Detailed Academic Explanation:
Coffee was not replaced because the preg_replace function is case sensitive. Therefore it treats coffee and Coffee differently.
💡Key Conceptual Anchor:Regular Expressions
Question 19 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following preg PHP functions is used to take a string, and put it in an array?
Correct Answer: Option B — preg_split()
Detailed Academic Explanation:
The string is broken up into different values in the array based upon your input.
💡Key Conceptual Anchor:Regular Expressions
Question 20 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $line = "You like dogs. I hate dogs. We should marry." $sen = preg_split ( '/./' , $line); print_r ($sen); ?>
Correct Answer: Option C — Array([0]=>You like dogs. [1]=>I hate dogs. [2]=>We should marry.)
Detailed Academic Explanation:
We use a ‘.’ period to split the data, therefor giving each sentence it’s own array entry.
💡Key Conceptual Anchor:Regular Expressions
Question 21 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following is not a preg PHP function?
Correct Answer: Option C — preg_matchall
Detailed Academic Explanation:
The function preg_matchall does not exist. preg_match_all is a preg function.
💡Key Conceptual Anchor:Regular Expressions
Question 22 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
PHP has long supported two regular expression implementations known as _______ and _______. 1. Perl 2. PEAR 3. Pearl 4. POSIX
Correct Answer: Option C — 1 and 4
Detailed Academic Explanation:
1 and 4 is the correct answer to “PHP has long supported two regular expression implementations known as _______ and _______. 1. Perl 2. PEAR 3. Pearl 4. POSIX”. This question is standard in competitive examination syllabi for Regular Expressions.
💡Key Conceptual Anchor:Regular Expressions
Question 23 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following regular expression matches any string containing zero or one p?
Correct Answer: Option C — P?
Detailed Academic Explanation:
P? is the correct answer to “Which one of the following regular expression matches any string containing zero or one p”. This question is standard in competitive examination syllabi for Regular Expressions.
💡Key Conceptual Anchor:Regular Expressions
Question 24 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
POSIX implementation was deprecated in which version of PHP?
Correct Answer: Option D — PHP 5.3
Detailed Academic Explanation:
PHP 5.3 is the correct answer to “POSIX implementation was deprecated in which version of PHP”. This question is standard in competitive examination syllabi for Regular Expressions.
💡Key Conceptual Anchor:Regular Expressions
Question 25 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
POSIX stands for
Correct Answer: Option A — Portable Operating System Interface for Unix
Detailed Academic Explanation:
Portable Operating System Interface for Unix is the correct answer to “POSIX stands for”. This question is standard in competitive examination syllabi for Regular Expressions.
💡Key Conceptual Anchor:Regular Expressions
Question 26 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following functions can be used to concatenate array elements to form a single delimited string?
Correct Answer: Option B — implode()
Detailed Academic Explanation:
implode() is the correct answer to “Which one of the following functions can be used to concatenate array elements to form a single delimited string”. This question is standard in competitive examination syllabi for Regular Expressions.
💡Key Conceptual Anchor:Regular Expressions
Question 27 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following functions finds the last occurrence of a string, returning its numerical position?
Correct Answer: Option D — strrpos()
Detailed Academic Explanation:
strrpos() is the correct answer to “Which one of the following functions finds the last occurrence of a string, returning its numerical position”. This question is standard in competitive examination syllabi for Regular Expressions.
💡Key Conceptual Anchor:Regular Expressions
Question 28 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following preg PHP function is used to do a find and replace on a string or an array?
Correct Answer: Option A — preg_replace()
Detailed Academic Explanation:
preg_replace() is the correct answer to “Which one of the following preg PHP function is used to do a find and replace on a string or an array”. This question is standard in competitive examination syllabi for Regular Expressions.
💡Key Conceptual Anchor:Regular Expressions
Question 29 of 29
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Parameter flags was added in which version of PHP?
Correct Answer: Option D — PHP 4.3
Detailed Academic Explanation:
PHP 4.3 is the correct answer to “Parameter flags was added in which version of PHP”. This question is standard in competitive examination syllabi for Regular Expressions.
💡Key Conceptual Anchor:Regular Expressions
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.