On Wed, 21 Dec 2005 18:03:13 -0000, DeZo <nobody / nowhere.com> wrote:

> Why does the following code:
>
> line = "  rows = 10  cols = 1  occupied cells = 0"
> line =~ /.*(\d+).*(\d+).*(\d+)/
> print("  scanned rows = ",$1," cols = ",$2," occ = ",$3,"\n")
>
> print this when it runs:
>
>   scanned rows = 0 cols = 1 occ = 0
>
> (notice rows is zero!)
>
> What have I done wrong?

Your problem is that '*' is greedy so it'll match as many 'any characters'  
as it can. Try

	/.*?(\d+).*?(\d+).*?(\d+)/

Usually I'd tend to use something like:

	/[^\d]*(\d+)[^\d]*(\d+)[^\d]*(\d+)/

instead, to make it explicit I want not digits, followed by digits, etc...

Hope that helps,
Ross

-- 
Ross Bamford - rosco / roscopeco.remove.co.uk