Reputation: 1086
I want to retrieve the free variables in a lambda expression. For example
\z.\x.(xy)
, where "\" stand for the Lambda symbol: through a regex, I need to get all the letters which don't follow a backslash. In my example, the free variables would be
{y}
since "y" is the only variable not bounded to "\". How could I do that? Thanks in advance.
Upvotes: 1
Views: 87
Reputation: 382130
You can use /\\(\w+)/g
and iterate with exec
:
var r = /\\(\w+)/g, m,
s = "\\z.\\x.(xy)";
while (m = r.exec(s)) console.log(m[1]);
It logs "z"
then "x"
.
To answer the new question:
To get the names not following a \
, you may use /([^\\]|^)(\w+)/g
(and use the second capturing group which is the third element in the returned array).
Upvotes: 1