1

In regular expressions, question mark sometimes is used for lazy repletion, and sometimes to indicate "The preceding is repeated one or more times."

Are these 2 usages of question mark in regex related to each other; or that they are not related, but happened to use the same character?

If they are related, then how does the following works?

<.+?>

  • If a question mark is added to a quantifier (including `?` itself), it marks that quantifier as lazy. In most other contexts it works as a quantifier (zero or one). In character classes and when backslash-escaped it is literal. – Sebastian Proske Mar 21 '17 at 19:57
  • The form you refer to is `something + quantifier + quantifier_qualifier`. The _qualifier_ is a question mark. When present, the quantifier is lazy, when not, it's greedy. Don't confuse the _qualifier_ with a quantifier, even though a question mark is a valid quantifier. –  Mar 21 '17 at 19:58
  • 1
    I think I get it now; +? are considered together as one operator; am I correct? I was considering .+ together and then thinking that ? is being applied to .+. But the fact is that +? is being applied to the period(.) which indicates any character. – Scott Bergstrom Mar 21 '17 at 20:33

0 Answers0