Why does this regular expression match multiple characters?

I can match "a" followed by at least 2 other characters before another "a" with the following regular expression.

a.{2,}?a

Interestingly, the inclusion of a question mark makes the regular expression match the instance with the least number of middle characters, therefore, for example, given the following line,

abbabbbba

the regular expression will match the leftmost abba instead of a solid line. Why does the inclusion of a question mark cause the regular expression to match the instance with the least number of middle characters?

+4
source share
2 answers

. , .

: regular-expressions.info

(?: | ) , hwnd.

+1

?

/. {2}? /

a ( )

. ( )

{2,} : 2

? , []

a ( )

+1

All Articles