I would like to know what the difference is between (.+?)
and (.*?)
(. *?) 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.
The difference is that: the * in this problem can match any sequence independently, while the * in Regex Matching would only match duplicates, if any, of the character prior to it.
* means any character occurring 0 or more times, a* means a appearing 0 or more times, and so on. Show activity on this post. In regular expressions * by itself does not mean anything. It modifies the expression in front of it.
- a "dot" indicates any character. * - means "0 or more instances of the preceding regex token"
The .+?
form requires at least one character to match, while .*?
can match none at all. Both operations are non-greedy, so they will try to find the shortest possible matching string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With