Reluctance against the greedy only makes sense when a variable length match is possible; a reluctant quantifier will correspond to the minimum possible and greedy maximum.
To distinguish behavior of a limited value, it must have a range, i.e. the quantity must have different minimum and maximum values. To illustrate:
Given input 1234567 , captured groups:
(\d{2,3})(\d+) -> (123)(4567) (\d{2,3}?)(\d+) -> (12)(34567)
When there is only a fixed value, for example \d{2} , is there no difference in behavior, adding ? .
source share