Page 1 of 1
Quotes in regular expressions
Posted: Wed Nov 29, 2000 12:41 pm
by Thunderstone
I have <img alt="getthisone" src="somepicture.gif">
What I need is just somepicture
but because there are many gifs on the same page I need the one with
alt="getthisone" src=" proceeding it.
The problem is with that initial quote. I ve tried escaping but
that is not working.
Paul
Quotes in regular expressions
Posted: Wed Nov 29, 2000 1:07 pm
by Thunderstone
Double quotes are escaped in Vortex strings by quoting the whole string
in single quotes instead, and vice versa. A better method, since this
is a REX expression, is to use a REX hex escape for the double-quote:
<rex '>><img alt\=\x22getthisone\x22 src\=\x22\P=[^\x22\.>]+' $txt>
Note the \x22 as an escape in REX for the double-quote char. A more
portable expression that makes fewer space and quoting assumptions might be:
<rex '>><img=\space+alt=\space*\==\space*\x22?getthisone=\x22?\space+src=\space*\==\space*\x22\P?[^\.\x22\space>]+' $txt>
While long, this expression will work regardless of whether the alt or
src is double-quoted, or the amount of whitespace between them. (It
does assume that alt comes first however.)
-Kai