When you say "Regex", you refer to several methods - this is not just a problem of the basic theory. Consider the question: "Does this string match my given regular expression?" For such a question, the concept of “greedy” is just a detail of the implementation - if you use one of the common (but inefficient) backtracking implementations, this can affect performance, but not output. Similarly, the question: "does this line contain a match?" it is not affected by greedy or non-greedy quantifiers. This first type of regular expression refers to the abstract concept of set-membership: the definition of the language of matching strings.
So why are there non-greedy quantifiers? Regular expressions are not just used for matching; general implementations can find where the match is and which parts of the regular expression match those parts of the output. By doing this, the user depends on the intricacies of the implementation, which is not trivial. This second type of regular expression is associated with getting a few bits of text into a more practical presentation with a language context that is not relevant to learning.
Typically, when you talk about the power of regular expression formalism, you are talking about the first world in which a computer answers simple yes or no. It’s easy to say because the specification is clear. When you talk about greedy and non-greedy quantifiers, you talk about the second world - used lots in practice, but with a specification that basically grew without much planning to solve real problems and is the standard due to backward compatibility, This second world solves completely different problems, and it’s not clear to me what even “expressive power” means here. Of course, non-living can be practical; and this question ...
Unwanted quantifiers do nothing for the first type of expressiveness, and they do for the second, although it is not entirely clear what “expressive power” means.
Eamon nerbonne
source share