Skip to main content

Regular Expressions MCQs with Explanations

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
Question 1 of 29
★ FPSC ★ PPSC

[:alpha:] can also be specified as.

Question 2 of 29
★ FPSC ★ PPSC

How many functions does PHP offer for searching strings using POSIX style regular expression?

Question 3 of 29
★ 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!" ; ?>

Question 4 of 29
★ 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)); ?>

Question 5 of 29
★ 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

Question 6 of 29
★ FPSC ★ PPSC

Which among the following is/are not a metacharacter? 1. /a 2. /A 3. /b 4. /B

Question 7 of 29
★ FPSC ★ PPSC

How many functions does PHP offer for searching and modifying strings using Perl-compatible regular expressions.

Question 8 of 29
★ 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); ?>

Question 9 of 29
★ 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()

Question 10 of 29
★ FPSC ★ PPSC

Which one of the following functions will convert a string to all uppercase?

Question 11 of 29
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php echo str_pad ( "Salad", 5)." is good." ; ?>

Question 12 of 29
★ 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." ; ?>

Question 13 of 29
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php $url = "contact@examveda.com" ; echo ltrim(strstr ($url, "@"),"@" ); ?>

Question 14 of 29
★ 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); ?>

Question 15 of 29
★ 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);?

Question 16 of 29
★ FPSC ★ PPSC

Which one of the following functions is used to search a string?

Question 17 of 29
★ 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" ; ?>

Question 18 of 29
★ 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); ?>

Question 19 of 29
★ FPSC ★ PPSC

Which one of the following preg PHP functions is used to take a string, and put it in an array?

Question 20 of 29
★ 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); ?>

Question 21 of 29
★ FPSC ★ PPSC

Which one of the following is not a preg PHP function?

Question 22 of 29
★ FPSC ★ PPSC

PHP has long supported two regular expression implementations known as _______ and _______. 1. Perl 2. PEAR 3. Pearl 4. POSIX

Question 23 of 29
★ FPSC ★ PPSC

Which one of the following regular expression matches any string containing zero or one p?

Question 24 of 29
★ FPSC ★ PPSC

POSIX implementation was deprecated in which version of PHP?

Question 25 of 29
★ FPSC ★ PPSC

POSIX stands for

Question 26 of 29
★ FPSC ★ PPSC

Which one of the following functions can be used to concatenate array elements to form a single delimited string?

Question 27 of 29
★ FPSC ★ PPSC

Which one of the following functions finds the last occurrence of a string, returning its numerical position?

Question 28 of 29
★ FPSC ★ PPSC

Which one of the following preg PHP function is used to do a find and replace on a string or an array?

Question 29 of 29
★ FPSC ★ PPSC

Parameter flags was added in which version of PHP?

✓ Link copied to clipboard
Continue Your Practice

Advance Html — Part 1

Master the next curriculum module with 40 exam-standard MCQs.

Next Practice Set →

💡 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.

More Modules in Programming & Software Development

View All →
📚

Study Guides

Topic summaries and syllabus breakdown

Explore Guides →
🎯

Complete Library

Search through 78,000+ verified MCQs

Browse Library →
📱

Mobile App

Offline mock tests and instant bookmarks

Get Mobile App →