in reply to perl regex with '\s+'
Hi,
As is frequently the case, the problem cames from misunderstunding greadines of RE + and * operators. Let us take
which is a simpler version of your RE, and try and match it against "___abc___def" (the "_" represents spaces). First, perl matches \s+ against the three spaces, and the first (.*) against all the other acaracters (that is "abc___def". But now there is a \s+, which require at least a space, so the first .* grundly gives back one character at time, until it only matches "abc__" (two spaces). Now \s+ matches this space, and the second (.*) is free to match "def". After that, $1 is "abc__", and $2 is "def"./\s+(.*)\s+(.*)/
I hope this explain things...
Cheers
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl regex with '\s+'
by emcb (Beadle) on Jun 09, 2002 at 01:32 UTC | |
by Anonymous Monk on Jul 02, 2012 at 13:46 UTC |