#!/usr/bin/perl
$word = "one last challenge";
if ( $word =~ /^(\w+).*\s(\w+)$/ )
{
print "$1";
print "\n";
print "$2";
}
The output shows that "$1" is with result one and "$2" is with result challenge. I am confused about how this pattern match expression works step by step. I request u guys` explanation. Thank u very much.
Hi thank u for your reply. I juz get confused that why ".*\s" does not match "last " Thank you
note that there is a whitespace after double-quoted last
---------- Post updated at 09:18 AM ---------- Previous update was at 09:17 AM ----------
Hi thank u for your reply. I juz get confused that why ".*\s" does not match "last " Thank you
note that there is a whitespace after double-quoted last
Note that the value of $2 is "last" with a single space at both ends.
Also note that $3 equals "challenge" without a newline at the end, due to which the $ prompt of the shell shows up right after those "==" characters.
Thank u for your reply.... But doesn`t anything match the pattern should be stored in $1,$2...$n???? U said it is matched but not stored in the $2 because it is not enclsoed within bracket....So what do u by that? I am new to Perl thank u ....for ur reply
First, please use proper English, not leetspeak or chat style abbreviations.
Second, it's all there. Regex, by default, match, but do not save what is matched. If you want to save the matches (extract them), you'll have to explicitly tell the state machine to do that, by enclosing the term to be saved in braces.
Also, Perl has a pretty good tutorial on regular expression, available via
Thank you very much.
Second, it's all there. Regex, by default, match, but do not save what is matched. If you want to save the matches (extract them), you'll have to explicitly tell the state machine to do that, by enclosing the term to be saved in brace
This is really what I need. This is the point. Thank you so much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!