newLISP Fan Club

Forum => Anything else we might add? => Topic started by: maq on August 04, 2005, 08:52:40 AM

Title: Escaping backslashes in append operation for use in regex
Post by: maq on August 04, 2005, 08:52:40 AM
I have a small issue getting a regex to work the way I want it to. I set a string to the following:
(set 'command-line "woot -r 45 -w 46")
And then I want to alternate through the command line options by comparing against a list of flags that I'm looking for. Say:
(set 'opts '("r" "w"))
So I want to do the following:
(dolist (o opts)
(if (find (append "-" o "s*(w*)(s*-|$)") command-line 0)
(do-something with $1)
)
)

However I don't get a match because the append takes out the "" before the s & w. when I try to escape the "" I get "\s" or "\w", which also does not match.  So my question is, how can I escape a backlash for an append to output only a singular ""?



Thanks in advance,

--maq
Title:
Post by: Sammo on August 04, 2005, 09:04:26 AM
try



(append "-" o {s*(w*)(s*-|$)})



in which I replaced the double-quote string delimiters with left and right brace string delimiters,



instead of



(append "-" o "s*(w*)(s*-|$)")



Using braces instead of double-quotes removes the need to treat the backslash characters with special care.



-- sam
Title:
Post by: maq on August 04, 2005, 10:19:29 AM
Thanks Sammo. That does the trick.



--maq