Thanks Bart. preg_replace looks pretty nice, but as you say is in a later version.
The specific functionality I was after was being able show/hide content based on which section of the site the user is in based on the top-level page (while avoiding design customisations). And then make it re-usable so it can be nested in multiple places within the site, update once, update everywhere, etc. I was doing this by inspecting the url. But a nuance of our system is we have replicated master/slave server setup, and the master url's don't match the slave url's 1:1, not even close.
How I've resolved it was this:
%globals_asset_url^contains:domain.slaver.au/top_name: do_stuff_here: ^trim%
%globals_asset_url^contains:domain.master.au/some_extra_nuisance/top_name: do_stuff_here: ^trim%
It works, but I didn't like it, specifically because 'do_stuff_here' is the same for both lines, but I've got to define it twice.
Then repeat that for each item you want to display/hide, in these cases lists of links, so a couple hundred lines of code (so far).
If I could have used regex in the ^contains modifier I could have captured both those conditions in the one line.
Also, I know could have been achieved a number of other ways (e.g. design customisations, pure css, keywords with HTML comment bracing, javascript) but each of these options was ruled out for one reason or another. Above approach is working for now, albeit more verbose than I would like.
Looks like I can look forward to this functionality in a later version.
Thanks