Escaping backslashes in append operation for use in regex

For the Compleat Fan
Locked
maq
Posts: 7
Joined: Tue Jan 18, 2005 6:20 am
Contact:

Escaping backslashes in append operation for use in regex

Post 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

Sammo
Posts: 180
Joined: Sat Dec 06, 2003 6:11 pm
Location: Loveland, Colorado USA

Post 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

maq
Posts: 7
Joined: Tue Jan 18, 2005 6:20 am
Contact:

Post by maq »

Thanks Sammo. That does the trick.

--maq

Locked