Quotes in regular expressions

Post Reply
User avatar
Thunderstone
Site Admin
Posts: 2504
Joined: Wed Jun 07, 2000 6:20 pm

Quotes in regular expressions

Post 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


User avatar
Thunderstone
Site Admin
Posts: 2504
Joined: Wed Jun 07, 2000 6:20 pm

Quotes in regular expressions

Post 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


Post Reply