On Jan 2, 2:58*am, Ahmad <ahmad.abdulgh...@gmail.com> wrote:
> When running the following example:
>
> $str="aaaaaa * bbbb";
> ($a,$b)= $str=~/(\w+)\s?(\w+)/;
> print $a,"\n",$b;
>
> The result is:
>
> aaaaa
> a
>
> Why do we get this result??? Can anybody explain it?
Christian already explained to you the difference between ? and +, but
perhaps you were also (or rather) confused about what \s actually is.
You may be thinking that \s means simply "whitespace". It actually
means "any single white-space character". It is any ONE character
from the group: space, tab, newline, carriage return, or vertical
tab. If you want to match more than one character in sequence, you
must use the quantifiers (+, or *, or {n}, depending on your needs)
Hope that helps,
Paul Lalli
|