-> > I am a bit confused in understanding regular
-> > expressions w.r.t the First Match and All Matches.
Case 1
--------------------------------------------------------------------------------
Regular Expression: .
First match: Regular expressions are powerful!!!
All matches: Regular expressions are powerful!!!
A dot "." matches "any" character, hence first match is the first character in
the string, and all matches shows that each of the characters matched,
Case 2
--------------------------------------------------------------------------------
Regular Expression: ......
First match: Regular expressions are powerful!!!
All matches: Regular expressions are powerful!!!
Six "." s in the pattern mean that match any 6 characters, hence "Regula" is
the first match, keeps on matching each 6 characters in the string, ends when
there are only 5 characters ( "ul!!!" ) left.
Try runngint hsi code to get clear idea:
#!/usr/local/bin/perl
$str= "Regular expressions are powerful!!!";
while ($str =~ /....../g) {
print "Word is - $&, ends at position ", pos $str, "\n";
}
Dhanashri