Page 1 of 1

Escaping backslashes in append operation for use in regex

Posted: Thu Aug 04, 2005 3:52 pm
by maq
I have a small issue getting a regex to work the way I want it to. I set a string to the following:

Code: Select all

(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:

Code: Select all

(set 'opts '("r" "w"))
So I want to do the following:

Code: Select all

(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

Posted: Thu Aug 04, 2005 4:04 pm
by Sammo
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

Posted: Thu Aug 04, 2005 5:19 pm
by maq
Thanks Sammo. That does the trick.

--maq