| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
13.2.7 Non-greedy quantifiers
The quantifiers described above are greedy, ie, they match the maximal number of instances that would still lead to an overall match for the full pattern.
(pregexp-match "<.*>" "<tag1> <tag2> <tag3>")
⇒ ("<tag1> <tag2> <tag3>")
|
To make these quantifiers non-greedy, append a ? to them.
Non-greedy quantifiers match the minimal number of instances needed to
ensure an overall match.
(pregexp-match "<.*?>" "<tag1> <tag2> <tag3>") ⇒ ("<tag1>")
|
The non-greedy quantifiers are respectively:
*?, +?, ??, {m}?, {m,n}?.
Note the two uses of the metacharacter ?.
