Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 4
    It's a POSIX requirement that the longest match be found for BRE and ERE. You can use perl or grep -P (when that's implemented with PCRE like with GNU grep, not ast-open's) for the other alternations not to be considered if a one further on the left matched. Commented Apr 11, 2020 at 20:43
  • @mosvy (1) Fact When you use a Tradition NFA engine, the order of the alternative in an alternation will be respected. This means that if the first alternative lead to a complete successful match, the other alternative will be ignored. Link Commented Apr 11, 2020 at 21:40
  • @mosvy (1) Also: Traditional NFA engines run so-called "greedy" match backtracking algorithms, testing all possible expansions of a regular expression in a specific order and accepting the first match. Note the word first.link Commented Apr 11, 2020 at 22:06