What will be the output of the above code snippet?
Answer
Correct Answer:
Copyright 2007
Note: This Question is unanswered, help us to find answer for this one
6. Which of the following statements are true about the \b PHP Regular Expression modifier?
Answer
Correct Answer:
If a match is not found using the \b modifier, it returns null.
Note: This Question is unanswered, help us to find answer for this one
7. Which of the following PHP Regular Expression modifiers finds any non digit character in a given string?
Answer
Correct Answer:
\D
Note: This Question is unanswered, help us to find answer for this one
8. Suppose you pass "a(bc)*" as a pattern to be matched to a specified string using PHP Regular Expressions. Which of the following strings does not match the above pattern?
Answer
Correct Answer:
bcde
Note: This Question is unanswered, help us to find answer for this one
9. Suppose you pass "world{2,3}" as a pattern to be matched to a specified string as shown in the code snippet below:
$pattern = "world{2,3}";
Which of the following strings does not match the above pattern?
Answer
Correct Answer:
world
Note: This Question is unanswered, help us to find answer for this one
Note: This Question is unanswered, help us to find answer for this one
21. Analyze the following code that uses the {x} PHP Regular Expression modifier:
<?php
$string = "10 or 100 or 1000?";
preg_match_all("/\d{2}/", $string,$matches);
foreach($matches[0] as $value)
{
echo $value;
}
?>
What will be the output of the above code snippet?
Answer
Correct Answer:
10101000
Note: This Question is unanswered, help us to find answer for this one
22. Analyze the following code:
<?php
$string = 'This is a [templateVar]';
preg_match_all("/[\[\]]/", $string, $matches);
foreach($matches[0] as $value)
{
echo $value;
}
?>
What will be the output of the above code snippet?
Answer
Correct Answer:
[]
Note: This Question is unanswered, help us to find answer for this one
23. Analyze the following code that uses the ?<= PHP Regular Expression modifier:
<?php
$string = 'I live in the whitehouse';
if(preg_match("/(?<!blue)house/i", $string))
{
echo 'Found a match';
}
else
{
echo 'No match found';
}
?>
What will be the output of the above code snippet?
Answer
Correct Answer:
Found a match
Note: This Question is unanswered, help us to find answer for this one
24. Which of the following PHP Regular Expression modifiers is used to put the Regex on multiple lines while at the same time allowing comments within the Regular Expression itself?
Answer
Correct Answer:
x
Note: This Question is unanswered, help us to find answer for this one
25. Analyze the following code snippet that uses the preg_grep() PHP Regular Expression method:
Array ( [0] => s [1] => t [2] => r [3] => i [4] => n [5] => g )
Note: This Question is unanswered, help us to find answer for this one
28. Which of the following characters is used to escape special characters in a given string during pattern matching using Regular Expressions?
Answer
Correct Answer:
\
Note: This Question is unanswered, help us to find answer for this one
29. Which of the following is the correct syntax for creating a Regular Expression in PHP?
Answer
Correct Answer:
preg_match("/^ABC/i", $string)
Note: This Question is unanswered, help us to find answer for this one
30. Suppose you perform pattern matching in a string using the \n PHP Regular Expression modifier. Which of the following values is returned if no newline character occurs in the string?
Answer
Correct Answer:
0
Note: This Question is unanswered, help us to find answer for this one
31. Which of the following PHP Regular Expression modifier is used to find a pattern at the beginning of a string?
Answer
Correct Answer:
^
Note: This Question is unanswered, help us to find answer for this one
32. Which of the following PHP Regular Expression modifiers is used to make as few matches as possible in a given pattern?
Answer
Correct Answer:
\U
Note: This Question is unanswered, help us to find answer for this one
33. Which of the following characters is found by a Regular Expression when the \s PHP modifier is set?
Answer
Correct Answer:
A newline character
Note: This Question is unanswered, help us to find answer for this one
What will be the output of the above code snippet?
Answer
Correct Answer:
1
Note: This Question is unanswered, help us to find answer for this one
35. Which of the following PHP Regular Expression modifiers finds zero or one occurrences of a specific character in a string?
Answer
Correct Answer:
?
Note: This Question is unanswered, help us to find answer for this one
36. Analyze the following code:
<?php
$string = "1, 100 or 1000?";
preg_match_all("/10*/",$string,$matches);
foreach($matches[0] as $value)
{
echo $value;
}
?>
What will be the output of the above code snippet?
Answer
Correct Answer:
11001000
Note: This Question is unanswered, help us to find answer for this one
37. Analyze the following code snippet that uses the preg_replace() PHP Regular Expression method:
<?php
$string = 'This is the {_FOO_} brought to you by {_BAR_}';
$template_vars=array("FOO" => "The PHP Way", "BAR" => "PHPro.orG");
$string = preg_replace("/{_(.*?)_}/ime", "\$template_vars['$1']",$string);
echo $string;
?>
What will be the output of the above code?
Answer
Correct Answer:
This is the The PHP Way brought to you by PHPro.orG
Note: This Question is unanswered, help us to find answer for this one
38. Suppose you pass "^.{3}$" as a pattern to be matched to a specified string using PHP Regular Expressions. Which of the following strings match the above pattern?
Answer
Correct Answer:
.3$
Note: This Question is unanswered, help us to find answer for this one
39. What is the [\b] PHP Regular Expression modifier used for?
Answer
Correct Answer:
It is used to match a single backspace character.
Note: This Question is unanswered, help us to find answer for this one
40. Suppose you use [hc]+at for pattern matching as a Regular Expression. Which of the following patterns does not match the above expression?
Answer
Correct Answer:
at
Note: This Question is unanswered, help us to find answer for this one
41. Analyze the following code snippet that uses the preg_last_error() PHP Regular Expression method:
<?php
preg_match('/(?:\D+|<\d+>)*[!?]/', 'foobar foobar foobar');
if (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR) {
echo 'Backtrack limit was exhausted!';
}
?>
What will be the output of the above code?
Answer
Correct Answer:
Backtrack limit was exhausted!
Note: This Question is unanswered, help us to find answer for this one
42. Which of the following PHP Regular Expression modifiers finds one or more occurrences of a specific character in a string?
Answer
Correct Answer:
+
Note: This Question is unanswered, help us to find answer for this one
43. Which of the following flags is used to include a newline character \n while using the dot meta character of PHP Regular Expressions?
Answer
Correct Answer:
\s
Note: This Question is unanswered, help us to find answer for this one
Regular Expressions With PHP Test MCQs | Topic-wise