Using the Perl-Compatible REs, you can control the greediness:
U (PCRE_UNGREEDY)
This modifier inverts the "greediness" of the quantifiers so
that they are not greedy by default, but become greedy if
followed by "?". It is not compatible with Perl. It can also
be set by a (?U) modifier setting within the pattern.
On 2001.11.14 06:01 Nikolai Devereaux wrote:
>
> I need to come up with a simple regexp that will find all substrings
> within
> a line that are surrounded by three single-quote marks.
>
> For example:
>
> $example = "Hello, all. '''How are''' you doing '''today'''?";
>
> $example = ereg_replace($PAT, $SUB, $example);
>
> Should successfully find "How are" AND "today". and replace them with
> $SUB.
>
> My naive approach, $PAT = "(''')(.*)(''')" of course will be greedy, and
> replace "How are you doing today" with $SUB.
>
> I've tried this, but it didn't work.:
>
> $PAT = "(''')([^(''')])(''')" and similarly
> $PAT = "(''')([^('){3}])(''')"
>
> Any help/suggestions would be appreciated.
>
> nik
>
>
>