Home>

I want to count the number of characters in a string that contains a regular expression.
Specifically, I think that m and n in the code below are expressed as the same character string.
It will be len (m) = 4, len (n) = 5.
I would like to know how to output the number of characters of n as 4.
Thank you.

Corresponding source code
import re
m = r "a ..."
n = r "a. {3}"
print (len (m))
print (len (n))
  • Answer # 1

    I think that m and n in the code below are expressed as the same character string.

    It will not be. Regular expression literals in PythonThere is noneSo as I wrotemIs'a ...'ThatStringis.

Trends