What is the difference between (.*?) and (.*)? in regex?

For regular expressions, what is the difference between (.*?) and (.*)??


I used the regex tester at regex101.com (no affiliation) to test these.

(.*?) matches any character (.) any number of times (*), as few times as possible to make the regex match (?). You'll get a match on any string, but you'll only capture a blank string because of the question mark. This feature is much more useful when you have a more complicated regex. Here, the parser doesn't have to capture anything at all to get a match: the asterisk allows any number of characters in the capturing group, while the question mark makes the parser save as many as possible from the input text for later, resulting in nothing being captured.

(.*)? captures a group zero or one times (?). That group consists of a run of any length (*) of any character (.). This also will match anything, but it will capture the first line, since the dot matches anything except a newline.