Home » Perl, Regular Expression

Fun with Regular Expression

15 August 2007 35 views One Comment Popularity: 1% Share/Bookmark

Fun with perl regular expression

A) $st = “The programming republic of perl”;

$1 = ?, $2 = ? and $3 = ?

1) if($st =~/(.*)(e|r)(.*)$/)

2) if($st =~/(m{1,2})(.*)$/)

3) if($st =~/(.*)(m{1,2})(.*)$/)

4) if($st =~/(.?)(m{1,2})(.*)$/)

5) if($st =~/(.+?)(e|r)(.*)$/)

6) if($st =~/(m{1,2}?)(.*?)$/)

7) if($st =~/(m{1,2}?)(.*?)/)

8 ) if($st =~/(.*})(.*)$/)

Answer:

1) $1 = The programming republic of pe $2 = r $3 = l

2) $1 = mm $2 = ing republic of perl $3 = -

3) $1 = The program $2 = m $3 = ing republic of perl

4) $1 = a $2 = mm $3 = ing republic of perl

5) $1 = Th $2 = e $3 = programming republic of perl

6) $1 = m $2 = ming republic of perl $3 = -

7) $1 = m $2 = - $3 = -

8 ) $1 = The programming republic of perl $2 = - $3 = -

B) $st = “Mississippi made a hissing sound”;

$1 = ?, $2 = ? and $3 = ?

1) if($st =~/(.*)(i|s)(.*)$/)

2) if($st =~/(s{1,2})(.*)$/)

3) if($st =~/(.*)(s{1,2})(.*)$/)

4) if($st =~/(.?)(s{1,2})(.*)$/)

5) if($st =~/(.+?)(i|s)(.*)$/)

6) if($st =~/(s{1,2}?)(.*?)$/)

7) if($st =~/(s{1,2}?)(.*?)/)

8 ) if($st =~/(.*})(.*)$/)

Answer:

1) $1 = Mississippi made a hissing $2 = s $3 = ound

2) $1 = ss $2 = issippi made a hissing sound $3 = -

3) $1 = Mississippi made a hissing $2 = s $3 = ound

4) $1 = i $2 = ss $3 = issippi made a hissing sound

5) $1 = m $2 = i $3 = ssissippi made a hissing sound

6) $1 = s $2 = sissippi made a hissing sound $3 = -

7) $1 = s $2 = - $3 = -

8 ) $1 = Mississippi made a hissing sound $2 = - $3 = -

C) $st = “Yahoo shooting hotmail semeeingly”;

$1 = ?, $2 = ? and $3 = ?

1) if($st =~/(.*)(h|o)(.*)$/)

2) if($st =~/(o{1,2})(.*)$/)

3) if($st =~/(.?)(e{1,2})(.*)$/)

4) if($st =~/(e{1,2}?)(.*?)$/)

Answer:

1) $1 = Yahoo shooting h $2 = o $3 = tmail semeeingly

2) $1 = oo $2 = shooting hotmail semeeingly $3 = -

3) $1 = s $2 = e $3 = meeingly

4) $1 = e $2 = meeingly $3 = -

D) $st = “zzen zest zzep zzengz”;

$1 = ?, $2 = ? and $3 = ?

1) if($st =~/(.*)(z|e)(.*)$/)

2) if($st =~/(z{1,2})(.?)(.*)$/)

3) if($st =~/(.*)(z{1,2})(.*)$/)

4) if($st =~/(.+?)(z|e)(.*)$/)

5) if($st =~/(z{1,2}?)(.*?)$/)

Answer:

1) $1 = zzen zest zzep zzeng $2 = z $3 = -

2) $1 = zz $2 = e $3 = n zest zzep zzengz

3) $1 = zzen zest zzep zzeng $2 = z $3 = -

4) $1 = z $2 = z $3 = en zest zzep zzengz

5) $1 = z $2 = - $3 = -

E) $test = “Communication comparison ammplification,”

$1 = ?, $2 = ? and $3 = ?

1) if($test =~/(.*)(m{1,2})(.*)/)

2) if($test =~/(.*?)(.*)/)

3) if($test =~/(.?)(m|p)(.*)/)

4) if($test =~/(.?)(^m|p)(.*?)/)

Answer:

1) $1 = Communication comparison am $2 = m $3 = plification,

2) $1 = $2 = Communication comparison amplification, $3 =

3) $1 = o $2 = m $3 = munication comparison amplification,

4) $1 = m $2 = p $3 =

F) $ip = “progra0mming456!is-+?fun!”

a) $ip =~tr/A-z/*/s;

b) $ip =~tr/A-z/ /cs;

c) $ip =~tr/A-z//sc;

Find the value of a),b) and c).

Answer:

a) $ip = *0*456!*-?*!

b) $ip = progra mming is fun

c) $ip = progra0mming456!is-+?fun!

From Mukesh Chapagain's Blog | Post Fun with Regular Expression

Related posts:

  1. Regular Expression check, Validation in PHP
  2. jQuery: Print array and object

One Comment »

  • Great Home Improvement Info said:

    Thanks for sharing this information. Really is pack with new knowledge. Keep them coming.

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.