find and string types

For the Compleat Fan
Locked
cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

find and string types

Post by cormullion »

I've forgotten why these two find expressions should give different results:

Code: Select all

(set 't "       ; this is a comment")
(find "(\s*)(;+?)(.*)" t 0) 
(find {(\s*)(;+?)(.*)} t 0) 
I ought to know...

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

In the first one, which is delimited by quotes you would have to escape the backslash with another backslash, which is not necessary in the second one, which is delimited by curly braces. Curly braces suppress pre processing and take the characters literally.

Code: Select all

> (find {(\s*)(;+?)(.*)} t 0) ; only single backslash needed
0
> (find "(\\s*)(;+?)(.*)" t 0) ;  double backslash necessary
0
> 

Lutz

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

Of course. I knew that.... Well, i should have remembered. Thanks Lutz!

Locked