Regex Question

Q&A's, tips, howto's
Locked
johnd
Posts: 18
Joined: Mon May 09, 2005 7:54 pm
Location: San Francisco, CA

Regex Question

Post by johnd »

How does newLISP control the value of system variables in regex? It seems they are set only on non-nil regex results.

> (regex ".*([aeiou]{2}).*" "Seattle")
("Seattle" 0 7 "ea" 1 2)
> $1
"ea"
> (regex ".*([aeiou]{2}).*" "San Francisco")
nil
> $1
"ea"
>

If this is the intended behavior it should probably be documented. I would argue that nil is a result and that $1 should return nil when the regex evaluates to nil. This was an issue recently because I was checking for $1 to be nil rather than the regex expression itself. The regex evaluated to nil but $1 retained a previous value.

John
[/i]

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

Post by cormullion »


Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

I disagree. I've put that side effect to good use in progressive logic. You can set $0 yourself between regexes. And you should always check the return value :)
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Locked