Strings and Regular Expressions
1.

PHP has long supported two regular expression implementations known as _______ and _______

i) Perl
ii) PEAR
iii) Pearl
iv) POSIX
A.  

i) and ii)

B.  

ii) and iv)

C.  

i) and iv)

D.  

ii) and iii)

2.

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

A.  

p+

B.  

p*

C.  

P?

D.  

p#

3.

[:alpha:] can also be specified as ________

A.  

[A-Za-z0-9]

B.  

[A-za-z]

C.  

[A-z]

D.  

[a-z]

4.

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

A.  

7

B.  

8

C.  

9

D.  

10

5.

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!";
    ?>
A.  

Error

B.  

Username must be all lowercase!

C.  

Username is all lowercase!

D.  

No Output is returned

6.

POSIX implementation was deprecated in which version of PHP?

A.  

PHP 4

B.  

PHP 5

C.  

PHP 5.2

D.  

PHP 5.3

7.

POSIX stands for ____________

A.  

Portable Operating System Interface for Unix

B.  

Portable Operating System Interface for Linux

C.  

Portative Operating System Interface for Unix

D.  

Portative Operating System Interface for Linux

8.

What will be the output of the following PHP code?

 <?php
    $text = "this is\tsome text that\nwe might like to parse.";
    print_r(split("[\n\t]",$text));
    ?>
A.  

this is some text that we might like to parse.

B.  

Array ( [0] => some text that [1] => we might like to parse. )

C.  

Array ( [0] => this is [1] => some text that [2] => we might like to parse. )

D.  

[0] => this is [1] => some text that [2] => we might like to parse.

9.

Which of the following would be a potential match for the Perl-based regular expression /fo{2,4}/?

i) fol
ii) fool
iii) fooool
iv) fooooool
A.  

Only i)

B.  

ii) and iii)

C.  

i), iii) and iv)

D.  

i) and iv)

 

10.

Which among the following is/are not a metacharacter?

i) \a
ii) \A
iii) \b
iv) \B
A.  

Only i)

B.  

i) and iii)

C.  

ii), iii) and iv)

D.  

ii) and iv)