...

View Full Version : preg_replace problem



mlse
02-16-2008, 03:59 PM
Hi all,

I want to replace strings matching the pattern {#<whatever>} (where whatever may vary) with the corresponding replacement, but only in unquoted strings. I know how to do this in all strings, but not in only unquoted ones.

for example:



$string = "The \"quick {#colour}\" {#animal} jumps over the '{#adjective} dog'";


I know how to get preg_replace to replace {#colour}, {#animal} and {#adjective} with replacement strings, BUT what (generic) pattern should I use to make preg_replace ignore {#colour} and {#adjective} and only replace {#animal}?

I.e. I want to ignore matching patterns in strings-within-the-string.

Any help much appreciated :)

shyam
02-16-2008, 08:23 PM
what you want to do cannot be done using a regex...you need to write a simple parser to handle quoted strings within strings

mlse
02-18-2008, 09:40 AM
I thought as much! Thanks anyway :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum