Matchchunk problem?

Dave Cragg dcragg at lacscentre.co.uk
Wed Feb 6 08:08:01 EST 2002


At 9:41 pm +1100 6/2/02, David Vaughan wrote:
>The following script:
>   put "frog frog"  into avar
>   put 1 into x
>   put 1 into y
>   get matchchunk(avar,"F*g",x,y)
>   put it  && x && y
>
>returns "true  "  ...so what happened to the chunk values expected
>in "x" and "y" ?
>What I was REALLY trying to test was whether it would return in x
>and y "1 4" or "1 9", but now I would love to know why I get neither
>(matchtext fails similarly). What have I done wrong?
>

This regex stuff needs a twisted mind to master. :)

Two problems with the script:

1. The regular expression "F*g" is trying to match "any number of F's 
, including none" followed by a "g". This means if there is a "g" 
anywhere in the text, it will match and thus return true.

I think you want "F.*g" ("F" followed by any number of characters 
followed by "g")

2.  To get values returned in the variables, you need to enclose the 
relevant part of the regex in parentheses.

on mouseUp
   put "frog frog"  into avar
   put 1 into x
   put 1 into y
   get matchchunk(avar,"(F.*g)",x,y)
   put it  && x && y
end mouseUp

It returns "true 1 9"

Cheers

Dave Cragg
(Revolution --It's got the power)



More information about the use-livecode mailing list