[pmwiki-users] Extended markup

Patrick R. Michaud pmichaud at pobox.com
Thu Apr 21 12:45:18 CDT 2005


On Thu, Apr 21, 2005 at 06:22:55PM +0100, Ciaran wrote:
> On 21/04/05, CB <chrisbar at wanadoo.fr> wrote:
> > Could someone explain me the question mark utility in the syntaxe of the
> > pattern part ?
> > For example :
> > 
> > Markup("em","inline","/''(.*?)''/","<em>$1</em>");
>  
> It has several names, the one that springs to mind is non-greedy. 
> whereas .* will attempt to match as *much* as possible  .*? will
> attempt to match the least   that satisfies the expression.

The other common names are "minimal" versus "maximal" matches.  
The difference is easiest to see when matching the above against 
something like

    His ''Foreword'' is really ''backwards''.

Using /''(.*?)''/  as a pattern would match <Foreword> (minimum
number of repetitions of .*), while using while using /''(.*)''/ 
as a pattern would match <Foreword'' is really ''backwards> ; i.e.,
the maximum repetitions of .* that result in a match.

Pm



More information about the pmwiki-users mailing list