5

In emacs lisp, there's the function posix-search-forward http://www.gnu.org/software/emacs/manual/html_node/elisp/POSIX-Regexps.html.

Does anyone have a full example showing its difference from search-forward-regexp?

7

As stated, the posix functions find the longest match in all situations:

Given the text aa and the regexp "a\\|aa", search-forward-regexp will find a and stop, while posix-search-forward will continue to backtrack over all alternatives and will find that aa is the longest match.

Also as stated, the posix approach is incompatible with non-greedy operators:

Given the text aa and the regexp "a+?" search-forward-regexp will find the minimal match a, but posix-search-forward will (greedily) find aa, simply ignoring the non-greedy modifier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.