You are not missing anything.

Subexpression matching means when you have an expression like


that you can get access to the exact text matched by the two
parenthesized subexpressions.

You asked about non-greedy regular expressions which were first
popularized by perl.

IIRC the Plan 9 regex library does not provide this at all; Bell Labs
code never did non-greedy regexp matching.

Rob and/or Russ can correct me if I'm wrong.

FWIW, tools from the GNU world also do not support non-greedy
matching, nor are such expressions part of POSIX.

Hope this helps,


> > russ has a great writeup on this.
> >
> > i think it covers all your questions.
> >
> > - erik

> I read trough some of that already yesterday. Anyway, am still
> puzzled. In the text of
> Regular Expression Matching Can Be Simple And Fast
> (but is slow in Java, Perl, PHP, Python, Ruby, ...)
> R. Cox writes:
> ---
> While writing the text editor sam [6] in the early 1980s, Rob Pike
> wrote a new regular expression implementation, which Dave Presotto
> extracted into a library that appeared in the Eighth Edition. Pike's
> implementation incorporated submatch tracking into an efficient NFA
> simulation but, like the rest of the Eighth Edition source, was not
> widely distributed.
> ...
> Pike's regular expression implementation, extended to support Unicode,
> was made freely available with sam in late 1992, but the particularly
> efficient regular expression search algorithm went unnoticed. The code
> is now available in many forms: as part of sam, as Plan 9's regular
> expression library, or packaged separately for Unix.
> ---
> But any manual page (regexp(6), that of sam) keeps completely silent
> about eg. any submatch tracking.
> So what's wrong? Can anybody clarify the situation for me or do I
> really have to read the codes?
> Ruda