I already understand that .*
means zero or more of any character, but Could someone explain how .*
in the following work and what it would match?
.*([a-m/]*).* .*([a-m/]+).* .*?([a-m/]*).*
The Match-zero-or-more Operator ( * ) This operator repeats the smallest possible preceding regular expression as many times as necessary (including zero) to match the pattern. `*' represents this operator. For example, `o*' matches any string made up of zero or more `o' s.
The dot matches any character, and the star allows the dot to be repeated any number of times, including zero. If you test this regex on Put a "string" between double quotes, it matches "string" just fine.
The dot represents an arbitrary character, and the asterisk says that the character before can be repeated an arbitrary number of times (or not at all).
(dot) operator is used to access class, structure, or union members. The member is specified by a postfix expression, followed by a . (dot) operator, followed by a possibly qualified identifier or a pseudo-destructor name. (A pseudo-destructor is a destructor of a nonclass type.)
the dot means anything can go here and the star means at least 0 times so .*
accepts any sequence of characters, including an empty string.
Each case is different:
.*([a-m\/]*).*
The first .*
will probably match the whole string, because [a-m/]
is not required to be present, and the first *
is greedy and comes first.
.*([a-m\/]+).*
The first .*
will match the whole string up to the last character that matches [a-m/]
since only one is required, and the first *
is greedy and comes first.
.*?([a-m\/]*).*
The first .*?
will match the string up to the FIRST character that matches [a-m/]
, because *?
is not greedy, then [a-m/]*
will match all it can, because *
is greedy, and then the last .*
will match the rest of the 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