What does. *, (.) * and [.] * mean when writing regular expressions in python?

topic description

as the title, I am a beginner. I have just learned regular expressions. If I want to know the specific use of periods, I casually make up a simple piece of code. Then it is found that the matching expressions are. , (.) and [.] * are matching results are quite different. I would like to ask the specific difference between these three and why there is such a result.

related codes

/ / Please paste the code text below (do not replace the code with pictures)
import re
s = "nhellonmy name isnBob"
r = re.findall (". *", s)
print (r)

r = re.findall ("(.) *", s)

r = re.findall ("[.] *", s)

Code results

the above code, when the match is. *, the result is like this.
clipboard.png

(.)*
clipboard.png
[.]*

clipboard.png
I don"t quite understand the latter two. I hope you can help me solve it. Thank you.
in addition, I think the meaning of the period in the regular expression is to match characters other than newline characters, so in the above code, why do you match an empty character""after matching the last character" b"?

Apr.29,2021

it's time to sacrifice the sharp weapon I have collected for many years. Whenever you have this kind of question, please click on here .

this tool, with tutorials, reference documentation, debugging, analysis, regular collection and sharing, is a must for home travel.


. *

match any non-newline character the matching result can be 0 do not care about the matching result

(.) *

is the same as above, except that this cares about the matching result and saves it to the group

[.] *

same as the first
Menu