Hi,
actually, that should print ' is '
the reason for that is that regexes will try to match the earliest possible
string, but as much as possible.
so in your case, you say:
find a whitespace # \s
find one or more word chars # \w+
find a white space # \s
and store that # ( )
and do that for the whole string # /g
so in effect, this regex will match on ' is ' and then not match again
(since you specified leading AND trailing white space)
basicly, this is doing What You Expect isn't it?
hth,
Jos
>
> I'm reading Jos Boumans "Perl Beginners Tutorial To Regular Expressions".
> I'm stuck with a problem. Jos writes:
>
> Also realise that $1 and friends store the contents of the last succesfull
> match...
> I wanted to check that and wrote this code:
>
> --------------------------------
> #!/usr/bin/perl -w
> use strict;
>
> my($string) = "This is a test!";
> my($ergebnis);
>
> $string =~ m/(\s\w+\s)/g;
> $ergebnis = $1;
> print("$ergebnis\n");
> --------------------------------
>
> Shouldn't a be printed?
> I'm runnig perl, v5.6.0 built for i586-linux.
> I wouldn't bother normally, but I'm trying to understand every bit of
> perl...
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]