NonGreedyRegexp

Howto get “minimal matching” on a particular \\(.*\\) sub expression, ie. howto write a non-greedy regular expressions as in Perl (.*?):

 \\(\\|.\\)*

A strict POSIX implementation will still match the above greedily, but most backtracking implementations will do the above match non-greedily, just as (.*?) would. The above hack works in Emacs versions earlier than 21.1.

In Emacs 21.1 and later versions Perl-like non-greedy syntax (.*?) has been implemented.

In either case the * and + special characters can be used to create a non-greedy regexp.


CategoryRegexp