[thelist] PHP REg Exp

Struan Donald struan at exo.org.uk
Tue Dec 18 09:20:30 CST 2007

* at 18/12 17:28 +0300 Fred Jones said:
> I am stuck with a simple Reg Exp. I want to do this:
> preg_replace('/(.*)__START_STYLE__([.,\n]*)__END_STYLE__(.*)/','<style>$2 
> </style>',$body);
> meaning to scan the multiline string $body, find __START_STYLE__, find 
> __END_STYLE__ and store any and all characters between them in $2.

As you say . matches everything but newlines. However there's a set
of pattern modifiers that change this, and other, behaviours of the
regular expression:


So, if you instead use this pattern:


( note the trailing s )

then it should do what you want. 


More information about the thelist mailing list