On 21 August 2003 17:03, Thaddeus J. Quintin wrote: > Lets say I'm trying to extract some data from an HTML > document. I want > to get the values of the 'src' attributes of various tags. > > For example- > <img src="http://www.yahoo.com"> > > here's the pattern I've been trying- > > /\bsrc=(['|"])[^\\1]*[\\1]/im > > Basically, match the 'src=' followed by some type of quote, followed > by stuff that's not the quote originally matched, followed by > the same quote. > > But, obviously, I can't run this, because the quotes in the pattern > close off the string I'm trying to create. > > Are there ways of working with quotes?
Just escape the quote like you've escaped the backslashes. If double-quoting: $pattern = "/\bsrc=(['|\"])[^\\1]*[\\1]/im"; If single-quoting (better, if you don't variable interpolation) you don't even need to escape the backslashes, so: $pattern = '/\bsrc=([\'|"])[^\1]*[\1]/im'; Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php