Regular expressions - detecting whitespace

Dar Scott dsc at swcp.com
Wed Aug 13 17:09:01 EDT 2003


On Wednesday, August 13, 2003, at 03:56 PM, Steve Gehlbach wrote:

> Jim Witte wrote:
>>
>>   BTW, if I execute 'put matchText( "this text" , "(g*)")', it 
>> returns true.  Certainly this is not a string of 'g's..  What am I 
>> doing wrong here
>
> In RegExp, "*" matches _zero_ or more of the previous chars. What you 
> want here is "(g+)" for one or more g's.  Kind of counter intuitive 
> since for ls or dir, the "*" has a slightly different meaning, ie, "ls 
> g*" will get all files starting with "g".  Not so in regexp.

In addition, the regex matches if the pattern is within, not just if it 
spans the string.  For the pattern to match the entire string, \A at 
the start and \z at the end (or the equivalent) are needed.  For 
example, "\Ag*\z" will match a string of zero or more g's.  It will 
match the empty string in the case of zero.

Dar Scott




More information about the use-livecode mailing list